Originally Posted by
Salem
How do you suppose to stop yourself doing something dumb like
fun = &numbers;
array = fun(letters);
Thanks for the reply.
I think I was a little aware that I have used statments:
Code:
myfunction fun = &numbers;
int a = 2;
int *y;
y = fun(&a); // fun, function pointer is pointing to int* numbers(int *); here
Then
Code:
char* array, letters[20] = {'v','i','v','e','n','\0'};
fun = &alphabets;
array = fun(letters); // fun, the function pointer is now pointing to char* alphabets(char []); here.
Error Message:
arshadnazeer@mybox:~/nit/wander$ gcc fp.c
fp.c: In function ‘main’:
fp.c:8:19: warning: initialization from incompatible pointer type [enabled by default]
myfunction fun = &numbers;
^
fp.c:14:6: warning: assignment from incompatible pointer type [enabled by default]
fun = &alphabets;
Please may I know how I could have one function pointer point to two unique function with diverse return types and function arguments.
Please explain my dumbness level.
The following are the error messages that I see during compilation by gcc compiler, Linux Ubuntu.
Thank you.