Please Can Anny One Tell What This Declaration Says ?

C

code break

typedef void(*FP);
FP UserMenuFunk[7];
FP UserFunk[7];

Please your comments on this help me lot .
 
R

rory.brandybuck

Possible typo:
`void(*FP)' should be replaced by `void(*FP)()'
that is `FP' is a function pointer to the function which takes no
argument
and return nothing. See example below:

#include <stdio.h>

typedef void(*FP)();
FP UserMenuFunk[7];
FP UserFunk[7];

void some_func() {
printf("some_func");
}

int main() {
UserMenuFunk[0] = some_func;
UserMenuFunk[0]();
}
 
H

Haroon Shafiq

Possible typo:
`void(*FP)' should be replaced by `void(*FP)()'
that is `FP' is a function pointer to the function which takes no
argument and return nothing. See example below:

not necessarily. look at the following code sample. Here FP is a
defined type that represents a void pointer. and UserMenuFunk and
UserFunk are arrays of type FP and size 7 each.

/*CODE BEGINS*/
#include <stdio.h>
typedef void(*FP);

int main (int argc, char* argv[]) {
FP UserMenuFunk[7];
FP UserFunk[7];
char *a = "blah blah blah\n";
int b = 125;
int i = 0;
while (i < 7) {
UserMenuFunk = a;
*(int*)&UserFunk = b;
i++;
}
i = 0;
while (i < 7) {
printf("%d: %s\n", *(int*)&UserFunk,
(char*)UserMenuFunk);
i++;
}
return 0;
/*CODE ENDS*/
 
S

S.Tobias

Please include context!
[context restored]

code break said:
typedef void(*FP);
FP UserMenuFunk[7];
FP UserFunk[7];

Please your comments on this help me lot .

Possible typo:
`void(*FP)' should be replaced by `void(*FP)()'

Maybe, maybe not. The declaration
typedef void(*FP);
is also valid and `FP' is type `pointer to void'.
that is `FP' is a function pointer to the function which takes no
argument

No, no, no. The declaration
typedef void(*FP)();
means the function takes unspecified number of arguments.
and return nothing. See example below:

#include <stdio.h>

typedef void(*FP)();
FP UserMenuFunk[7];
FP UserFunk[7];

void some_func() {
printf("some_func");
}

void some_func1(int x, int y) { /*...*/ }
int main() {
UserMenuFunk[0] = some_func;
UserMenuFunk[0]();
UserMenuFunk[1] = some_func1;
UserMenuFunk[1](7, 11); /* ok */
 
B

Barry Schwarz

typedef void(*FP);
FP UserMenuFunk[7];
FP UserFunk[7];

Please your comments on this help me lot .

The parentheses are just a confusion factor.

FP is a typedef (synonym) for pointer to void.

UserMenuFunck and UserFunk are each an array of 7 pointer to void.

If the typedef had been void "(*FP)()" (at least the original
parentheses would make sense), then FP would have been a synonym for
pointer to function.


Remove del for email
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top