Who can explain the sentence for me?

S

Servé Lau

huhu said:
Hi,
I meet a sentence:

an array of function pointers is declared and initialized. The functions
have a struct intNode * as return value and expect no parameters.
 
J

jacob navia

huhu said:
Hi,
I meet a sentence:
------------------------------------------------
struct intNode *(*fpt[])(void)=
{createList, inNode, delNode,revNode,NULL};
-------------------------------------------------
The "createList","inNode","delNode","revNode" are functions.
I'm puzzled by the c sentence.
Who can explain it for me?
Thanks!
fpt is a table of functions that return a pointer to an "intNode" and
receive no arguments. This table contains 5 positions, the first four are
filled with the
respective functions, and the fifth position is NULL.

C can be very concise. More probably than is needed... :)
 
B

Barry Schwarz

Hi,
I meet a sentence:
------------------------------------------------
struct intNode *(*fpt[])(void)=
{createList, inNode, delNode,revNode,NULL};
-------------------------------------------------
The "createList","inNode","delNode","revNode" are functions.
I'm puzzled by the c sentence.
Who can explain it for me?
Thanks!
fpt is a 1-D array of unspecified quantity of pointer to function
(each of the functions pointed to be elements of the array)
taking no parameters
returning pointer to struct intNode

The array is initialized with five values (and the unspecified
quantity mentioned above is now determined to be five):
the address of the function createList
the address of the function inNode
....
the value of the NULL pointer constant


<<Remove the del for email>>
 
D

Dan Pop

huhu said:
Hi,
I meet a sentence:
------------------------------------------------
struct intNode *(*fpt[])(void)=
{createList, inNode, delNode,revNode,NULL};
-------------------------------------------------
The "createList","inNode","delNode","revNode" are functions.
I'm puzzled by the c sentence.
Who can explain it for me?
Thanks!
fpt is a table of functions that return a pointer to an "intNode" and
receive no arguments. This table contains 5 positions, the first four are
filled with the
respective functions, and the fifth position is NULL.

C can be very concise. More probably than is needed... :)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That's one of the reasons it comes with the typedef thing :)

A single typedef could turn that monster declaration into something
that even a beginner could read.

Dan
 
A

Alex Monjushko

huhu said:
Hi,
I meet a sentence:
------------------------------------------------
struct intNode *(*fpt[])(void)=
{createList, inNode, delNode,revNode,NULL};
-------------------------------------------------
The "createList","inNode","delNode","revNode" are functions.
I'm puzzled by the c sentence.
Who can explain it for me?
Thanks!

There is no such thing as a sentence in C.

'fpt' is defined as an array of pointers to functions which take
no arguments and return a pointer to 'struct intNode'. It is
subsequently initialized with what are probably pointers to
functions that meet these critera.

I recommend that you consult your favorite C book.
 
J

John Bode

huhu said:
Hi,
I meet a sentence:
------------------------------------------------
struct intNode *(*fpt[])(void)=
{createList, inNode, delNode,revNode,NULL};
-------------------------------------------------
The "createList","inNode","delNode","revNode" are functions.
I'm puzzled by the c sentence.
Who can explain it for me?
Thanks!

fpt -- fpt
fpt[] -- is an array
*fpt[] -- of pointers
(*fpt[])() -- to functions
(*fpt[])(void) -- taking no parameters
*(*fpt[])(void) -- returning pointers
struct intNode *(*fpt[])(void) -- to struct intNode

and the prototypes for the functions in the array are

struct intNode *createList (void);
struct intNode *inNode (void);
struct intNode *delNode (void);
struct intNode *revNode (void);

Calling fpt[0]() is the same as calling createList(), fpt[1]() is the
same as calling inNode(), etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top