473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C structure question

Hello all,
I am analysing 2.4 and 2.6 series ip_output.c file code. What i
found is that 2.6 kernel initialised
ip_packet_type with following definition
static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv,
};

And 2.4 have following definition.
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP),
NULL, /* All devices */
ip_rcv,
(void*)1,
NULL,
};
Why . is used in 2.6 series kernels and not in 2.4 series?Also other
structure members are why not necessary to define in 2.6 kernel?
regards,
linux_lover.
Nov 14 '05 #1
4 1541
linux.lover wrote:
Hello all,
I am analysing 2.4 and 2.6 series ip_output.c file code. What i
found is that 2.6 kernel initialised
ip_packet_type with following definition
static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv, ^^ Are you sure this comma is there? };

And 2.4 have following definition.
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP),
NULL, /* All devices */
ip_rcv,
(void*)1,
NULL, ^^ Are you sure this comma is there? };
Why . is used in 2.6 series kernels and not in 2.4 series?Also other
structure members are why not necessary to define in 2.6 kernel?


The 2.6 code (based on either the C99 standard or gcc, no doubt) allows
one to write initializations knowing only the names of the relevant
members of the struct. The 2.4 code (based on C90) requires one to know
the order of the members of the struct, including those that are not
relevant if they precede any of the relevant ones.

Note the members that you don't care about in the 2.4 code:
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP), /* relevant */
NULL, /* NOT relevant */
ip_rcv, /* relevant */
(void*)1, /* NOT relevant */
NULL /* NOT relevant */
};

It appears that the (void *)1 for the fourth member is not needed as
more than a place holder and that the final NULL is silly. Even so, the
pruned down initialization requires that you know that you are
initializing the first and second elements:

static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP), /* relevant */
NULL, /* NOT relevant */
ip_rcv /* relevant */
};
Nov 14 '05 #2
Martin Ambuhl <ma*****@earthlink.net> wrote:
linux.lover wrote:

static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv,

^^ Are you sure this comma is there?


There's nothing wrong with the trailing comma in a compound
initializer. See 6.7.8 syntax and examples 3 and 9.
};


--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #3
S.Tobias wrote:
Martin Ambuhl <ma*****@earthlink.net> wrote:
linux.lover wrote:


static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv,


^^ Are you sure this comma is there?

There's nothing wrong with the trailing comma in a compound
initializer. See 6.7.8 syntax and examples 3 and 9.


If you've been in comp.lang.c for more than 15 minutes, you know that I
tell people when something is wrong. I don't ask questions like the one
above. Silly twit.
Nov 14 '05 #4
Martin Ambuhl <ma*****@earthlink.net> wrote:
S.Tobias wrote:
Martin Ambuhl <ma*****@earthlink.net> wrote:
linux.lover wrote: static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv,

^^ Are you sure this comma is there? There's nothing wrong with the trailing comma in a compound
initializer. See 6.7.8 syntax and examples 3 and 9.

If you've been in comp.lang.c for more than 15 minutes, you know that I
tell people when something is wrong. I don't ask questions like the one
above. Silly twit.


:-)
You had me doubt for a while.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
1
by: Sean W. Quinn | last post by:
Hey folks, I have a question regarding file handling, and the preservation of class structure. I have a class (and I will post snippets of code later in the post) with both primitive data...
10
by: ranjeet.gupta | last post by:
Dear All !! Before i qoute my querry, I will like to qoute my analysis and my Knowledge Struct a { int raw; char data; };
10
by: Qwert | last post by:
Hello, is it correct that if a type (System.Type) is a value (.IsValueType=True) and not primitive (.IsPrimitive=False), that type is a structure? Thanks.
6
by: James | last post by:
I am using vb.net and need to keep in memory a large data structure, so I am looking for the best option. And after several test I am pretty confused. So I will be grateful if anyone can help me. ...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
1
by: =?Utf-8?B?VGhvbWFzUg==?= | last post by:
Hi together, I have following little problem with a structure which I need for unmanaged code: Public Structure Info Public Header As HeaderInfo ...
8
by: Andrew Smallshaw | last post by:
I'm working on a data structure that began life as a skip list derivative, but has evolved to the point that it now only has a passing resemblance to them. Each node of this structure has a few...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.