Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C structure question

Reply
Thread Tools

C structure question

 
 
linux.lover
Guest
Posts: n/a
 
      01-16-2005
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.
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-16-2005
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 */
};
 
Reply With Quote
 
 
 
 
S.Tobias
Guest
Posts: n/a
 
      01-16-2005
Martin Ambuhl <(E-Mail Removed)> 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 http://www.velocityreviews.com/forums/(E-Mail Removed)LID | sed s/[[:upper:]]//g`
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-17-2005
S.Tobias wrote:
> Martin Ambuhl <(E-Mail Removed)> 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.
 
Reply With Quote
 
S.Tobias
Guest
Posts: n/a
 
      01-17-2005
Martin Ambuhl <(E-Mail Removed)> wrote:
>S.Tobias wrote:
>> Martin Ambuhl <(E-Mail Removed)> 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 (E-Mail Removed)LID | sed s/[[:upper:]]//g`
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between c structure and c++ structure raghunandan_1081@yahoo.com C++ 9 11-11-2011 07:34 AM
How to read a Structure from a matlab file to a structure in Vc++ 2003 meisterbartsch C++ 2 06-12-2007 08:47 PM
Memory allocation in Structure to Structure pra_ramli@rediffmail.com C++ 2 03-09-2006 05:51 AM
Copy String structure "A" to string structure "B" Leo Nunez C Programming 3 02-09-2005 05:14 AM
Pointers to structure and array of structure. Excluded_Middle C Programming 4 10-26-2004 05:39 AM



Advertisments