|
-
Oct 3rd, 2002, 06:46 AM
#1
Thread Starter
PowerPoster
C: Function Pointer??
I'm having considerable trouble getting some function pointers to work. The idea is, that a function has an array of strings, it wants to pass the first element to a function, which will check it, and return the address of a function based on what that element is. The returned function should take an array of strings as a parameter.
I've got a function definition:
int (*checkBuiltInts(char s[]))(char *p[])
which I want to return the address of one of several functions defined as:
int functionToReturn(char *p[])
In the calling function, I have:
char **args
int (*builtInFunction(char *params[]))
I am trying to use
builtInFunction = checkBuiltIns(args)
but I get "invalid lvalue in assignment" error on that line...
anyone able to solve this for me?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 07:28 AM
#2
I wonder that "int (*checkBuiltInts(char s[]))(char *p[])" compiles at all. "char **args
int (*builtInFunction(char *params[]))" this too.
Your definitions confuse me. I suggest using typedefs.
typedef int (*ReturnedFunc)(char *[]);
Declare the function that returns a function pointer like this:
ReturnedFunc GetHandlerFunc(whatever);
Use it like this:
ReturnedFunc pFunc = GetHandlerFunc(whatever);
Then call the returned functions like this:
int i = pFunc(arStr);
Some people prefer this syntax, but htey are equivalent:
int i = (*pFunc)(arStr);
Always use typedefs when messing with function pointers, else it gets too confusing.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 3rd, 2002, 07:37 AM
#3
Thread Starter
PowerPoster
Okey dokey.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|