473,385 Members | 1,356 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,385 software developers and data experts.

Strange sintax

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
Apr 2 '08 #1
7 1404
In article <99**********************************@b64g2000hsa. googlegroups.com>,
InuY4sha <in******@email.itwrote:
>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
Apr 2 '08 #2
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.
Apr 2 '08 #3
Walter Roberson wrote:
In article
<99**********************************@b64g2000hsa. googlegroups.com>,
InuY4sha <in******@email.itwrote:
>>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.
Apr 2 '08 #4
ro******@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[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\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;}
Apr 2 '08 #5
On Apr 2, 9:06*am, Ben Pfaff <b...@cs.stanford.eduwrote:
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).
Apr 2 '08 #6
user923005 <dc*****@connx.comwrites:
On Apr 2, 9:06*am, Ben Pfaff <b...@cs.stanford.eduwrote:
>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
Apr 2 '08 #7
"Ben Pfaff" <bl*@cs.stanford.eduwrote in message
news:87************@blp.benpfaff.org...
user923005 <dc*****@connx.comwrites:
>On Apr 2, 9:06 am, Ben Pfaff <b...@cs.stanford.eduwrote:
>>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

Apr 2 '08 #8

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

Similar topics

5
by: Sam | last post by:
Guys facing a strange problem any clue would really rescue me.. i am using a ASP application with following things Server : Intel Xeon (TM) CPU 2GHz, 2GB RAM, 136GB HDD OS : Windows 2000...
2
by: Arthur | last post by:
I've come across some strange xml, that I need to deal with, it looks like this:- <root> <foo attr="1">Some random strange text. <bar attr="2">blar</bar> <bar attr="3">blar blar</bar> <bar...
2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
7
by: Alberto | last post by:
I have this store procedure to insert orders in the 'Orders' table of NorthWind (SQL Server 2000): CREATE PROCEDURE NuevoPedido ( @CustomerID nchar(5), @EmployeeID int, @OrderDate ...
1
by: simon | last post by:
This works in VB: <td <%# myFunction(DataBinder.Eval(Container.DataItem,"column1"))%>> but in C# doesn't. What is the right sintax to include some text between the html tag in C#? I can't...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
20
by: SpreadTooThin | last post by:
I have a list and I need to do a custom sort on it... for example: a = #Although not necessarily in order def cmp(i,j): #to be defined in this thread. a.sort(cmp) print a
14
by: blumen | last post by:
Hi all, I'm a newbie in VB.Net Programming.. Hope that some of you can help me to solve this.. I'm working out to read,parse and save textfile into SQL Server. The textfile contains thousands...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.