LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2006, 06:17 PM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
C syntax


i m very unsure of what this line means exactly:

typedef int (*initcall_t)(void);

why is there a void there?

i would think this typedef means that we can use another name for a pointer to an integer called initcall_t....what does the void do?
OR
is it a pointer to a function? why is there a typedef there in that case? is it typedef'ing' the integer that the function returns? what is the point of this?

i would very much appreciate a prompt reply!
Thank you!

Ashlesha.
 
Old 07-04-2006, 06:33 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Literally, the declaration is:

initcall_t is a pointer to a function taking no arguments (void arg list) and returning an int. 'typedef'ing it makes it look like it is a native data type.

--- rod.
 
Old 07-04-2006, 06:38 PM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
It is a pointer-to-function typedef, so that you can easily make code that takes one of them without trying to deal with the tough and possibly confusing syntax. All you need to do is declare things with that type, which is a lot simpler than if you had to do it the hard way everywhere.
 
Old 07-04-2006, 06:41 PM   #4
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
thank you very much...

i have another query

#define __setup(str, fn) \
static char __setup_str_##fn[] __initdata = str; \
static struct kernel_param __setup_##fn __attribute__((unused)) __initsetup = { __setup_str_##fn, fn }

#endif

what does this do?
i dont understand the use of ## in the definitions..

thankyou!
a
 
Old 07-04-2006, 06:43 PM   #5
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
tuxdev-

i m trying to figure out the kernel code for a mips microprocessor....

m using debian linux on my pc..

ashlesha.
 
Old 07-04-2006, 07:31 PM   #6
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
## is used to textually concatenate two things together, usually one (or both) of them a parameter. Say you want to make one long string out of a parameter and a fixed value. In the macro definition, you can use "a_long_ ## param". If param is "foo" the result is "a_long_foo" or if param is "bar" you get "a_long_bar". See the CPP documentation for details.
 
Old 07-04-2006, 07:53 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
It might help for us to know what file this comes out of, or the general purpose of this macro (beyond just setup). Setup what?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with syntax dr3vi1 Linux - Newbie 7 08-09-2005 10:20 AM
Help with lp syntax slick_willie Programming 2 02-03-2005 07:18 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
syntax lynger Linux - Software 6 12-02-2003 01:03 AM
C syntax help please ... DarkDrive Programming 2 08-07-2003 04:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration