Hi all :)
sorry.. I know this is a very mean question but I can't get the
following couple of lines:
static int dev_init(struct net_device *dev);
struct net_device my_device = { init: dev_init, };
To me it looks something like defining a function and creating a
structure that stores a label referencing that function.. what's the
scope behind this ?
Also I don't get the comma after "dev_init"...
Can somebody explain me this sintax please ?
Thanks in advance,
RM
|
|
0
|
|
|
|
Reply
|
inuY4sha1 (12)
|
4/2/2008 8:58:16 AM |
|
In article <9906693a-e3ed-468e-83af-e0d045c71e43@b64g2000hsa.googlegroups.com>,
InuY4sha <inuY4sha@email.it> wrote:
>sorry.. I know this is a very mean question but I can't get the
>following couple of lines:
> static int dev_init(struct net_device *dev);
> struct net_device my_device = { init: dev_init, };
>To me it looks something like defining a function and creating a
>structure that stores a label referencing that function.. what's the
>scope behind this ?
I suspect it is C99 and it means that the my_device field
named 'init' is to be initialized to the function pointer dev_init .
>Also I don't get the comma after "dev_init"...
>Can somebody explain me this sintax please ?
C99 allows an extra comma at the end of an initialization list.
It tends to make code easier to maintain.
--
"MAMA: Oh--So now it's life. Money is life. Once upon a time freedom
used to be life--now it's money. I guess the world really do change.
WALTER: No--it was always money, Mama. We just didn't know about it."
-- Lorraine Hansberry
|
|
0
|
|
|
|
Reply
|
roberson2 (8067)
|
4/2/2008 9:09:18 AM
|
|
InuY4sha wrote:
> Hi all :)
> sorry.. I know this is a very mean question but I can't get the
> following couple of lines:
> static int dev_init(struct net_device *dev);
> struct net_device my_device = { init: dev_init, };
> To me it looks something like defining a function and creating a
> structure that stores a label referencing that function.. what's the
> scope behind this ?
It's not a label, it's a field name. But this is not standard, and also
deprecated by gcc. You should use the standard way:
struct net_device my_device = { .init = dev_init, };
> Also I don't get the comma after "dev_init"...
> Can somebody explain me this sintax please ?
Just like other initialization, the last comma doesn't matter here.
--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
|
|
0
|
|
|
|
Reply
|
xiyou.wangcong (255)
|
4/2/2008 9:14:30 AM
|
|
Walter Roberson wrote:
> In article
> <9906693a-e3ed-468e-83af-e0d045c71e43@b64g2000hsa.googlegroups.com>,
> InuY4sha <inuY4sha@email.it> wrote:
>>sorry.. I know this is a very mean question but I can't get the
>>following couple of lines:
>> static int dev_init(struct net_device *dev);
>> struct net_device my_device = { init: dev_init, };
>>To me it looks something like defining a function and creating a
>>structure that stores a label referencing that function.. what's the
>>scope behind this ?
>
> I suspect it is C99 and it means that the my_device field
> named 'init' is to be initialized to the function pointer dev_init .
No. C99 uses the ".identifier" form.
And yes, 'init' should be a member of the net_device struct, and a function
pointer of that type like dev_init().
--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
|
|
0
|
|
|
|
Reply
|
xiyou.wangcong (255)
|
4/2/2008 9:19:13 AM
|
|
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
> In article <9906693a-e3ed-468e-83af-e0d045c71e43@b64g2000hsa.googlegroups.com>,
> InuY4sha <inuY4sha@email.it> wrote:
>>sorry.. I know this is a very mean question but I can't get the
>>following couple of lines:
>> static int dev_init(struct net_device *dev);
>> struct net_device my_device = { init: dev_init, };
>>To me it looks something like defining a function and creating a
>>structure that stores a label referencing that function.. what's the
>>scope behind this ?
>
> I suspect it is C99 and it means that the my_device field
> named 'init' is to be initialized to the function pointer dev_init .
The C99 syntax for a designated initializer is:
struct net_device my_device = { .init = dev_init, };
I think the "field_name:" form is a GCCism.
--
Ben.
|
|
0
|
|
|
|
Reply
|
ben.usenet (6515)
|
4/2/2008 9:24:09 AM
|
|
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
> C99 allows an extra comma at the end of an initialization list.
So does C89.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
|
|
0
|
|
|
|
Reply
|
blp (3953)
|
4/2/2008 4:06:41 PM
|
|
On Apr 2, 9:06=A0am, Ben Pfaff <b...@cs.stanford.edu> wrote:
> rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
> > C99 allows an extra comma at the end of an initialization list.
>
> So does C89.
There are some compilers that will blow a gasket, though (e.g. those
for OpenVMS).
|
|
0
|
|
|
|
Reply
|
dcorbit (2696)
|
4/2/2008 7:57:24 PM
|
|
user923005 <dcorbit@connx.com> writes:
> On Apr 2, 9:06�am, Ben Pfaff <b...@cs.stanford.edu> wrote:
>> rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>> > C99 allows an extra comma at the end of an initialization list.
>>
>> So does C89.
>
> There are some compilers that will blow a gasket, though (e.g. those
> for OpenVMS).
Then they aren't C89 compilers.
C99 did add the ability to add a trailing comma in one context:
within the list of enumerated values in an enum definition.
--
"All code should be deliberately written for the purposes of instruction.
If your code isn't readable, it isn't finished yet."
--Richard Heathfield
|
|
0
|
|
|
|
Reply
|
blp (3953)
|
4/2/2008 8:25:45 PM
|
|
"Ben Pfaff" <blp@cs.stanford.edu> wrote in message
news:877ifg9f7a.fsf@blp.benpfaff.org...
> user923005 <dcorbit@connx.com> writes:
>
>> On Apr 2, 9:06 am, Ben Pfaff <b...@cs.stanford.edu> wrote:
>>> rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>>> > C99 allows an extra comma at the end of an initialization list.
>>>
>>> So does C89.
>>
>> There are some compilers that will blow a gasket, though (e.g. those
>> for OpenVMS).
>
> Then they aren't C89 compilers.
True enough, but I have to use them.
;-)
> C99 did add the ability to add a trailing comma in one context:
> within the list of enumerated values in an enum definition.
> --
> "All code should be deliberately written for the purposes of instruction.
> If your code isn't readable, it isn't finished yet."
> --Richard Heathfield
--
Posted via a free Usenet account from http://www.teranews.com
|
|
0
|
|
|
|
Reply
|
dcorbit (2696)
|
4/2/2008 11:01:23 PM
|
|
|
8 Replies
24 Views
(page loaded in 0.415 seconds)
Similiar Articles: A strange syntax in the code - comp.soft-sys.matlabhi guys, i met a very strange code in some paper. function output = mymle(logdensity,x,del,param0,varargin) objfun = @(param) (-logdensity2loglik... JTextPane - syntax highlighting - comp.lang.java.guiA strange syntax in the code - comp.soft-sys.matlab JTextPane - syntax highlighting - comp.lang.java.gui A strange syntax in the code - comp.soft-sys.matlab JTextPane ... Getting an error: Syntax error at the end of input - comp.unix ...A strange syntax in the code - comp.soft-sys.matlab Getting an error: Syntax error at the end of input - comp.unix ... A strange syntax in the code - comp.soft-sys.matlab ... Word Macro to Objrexx - comp.lang.rexxA strange syntax in the code - comp.soft-sys.matlab Word Macro to Objrexx - comp.lang.rexx A strange syntax in the code - comp.soft-sys.matlab Word Macro to Objrexx - comp ... Strange large numbers represents dates - comp.databases.btrieve ...Convert DATE to NUMBER - comp.lang.awk What is that strange syntax supposed to mean? > > 0")] ... one or more date vectors DateVector to serial date numbers ... time ... Function definitions are not permitted in this context. - comp ...A strange syntax in the code - comp.soft-sys.matlab Function definitions are not permitted in this context - comp.soft ... A strange syntax in the code - comp.soft-sys ... Strange Length of an array ?? - comp.lang.xharbourStrange 'length' variable in javascript when using 'with' statement // here is a mystery array with strange value within. // it will work even out of 'with' statement ... Mysterious java error - comp.soft-sys.matlabA strange syntax in the code - comp.soft-sys.matlab > Java VM Version: Java 1.3.1_01 with ... can't see the code to ... am then able to cut/copy/paste the component.Two weird ... skill: strange symbolic assignment - comp.cad.cadence... to do with the two modes of the SKILL parser - "infix" (which is the C-like syntax ... comp.cad.cadence - page 2 | Computer Group skill: strange symbolic assignment scosmo ... Convert DATE to NUMBER - comp.lang.awkWhat is that strange syntax supposed to mean? > > 0")] > > gawk -v d=09/01/2007 -f fff ... It's impossible to see whether that's an effect of the above illegal syntax or ... Strange Statement | Free Music, Tour Dates, Photos, VideosStrange Statement's official profile including the latest music, albums, songs, music videos and more updates. Strange Statement | FacebookTo connect with Strange Statement, sign up for Facebook today. Sign Up Log In. Like Strange Syntax Speaker - Television Tropes & IdiomsThe Strange Syntax Speaker trope as used in popular culture, with a list of examples from all media. Strange StatementStrange Statement was formed on July 17th 2007 by the founder, Shawn Bailey. The band is currently made up of: Shawn Bailey (Singer) Adam Kaminski (Lead Guitarist ... Strange Syntax HelpI'm new to C# and can write a simple interest calculator, but not without this before it. What is the breakdown of this syntax? using System; namespace ... 6/19/2012 6:27:54 AM
|