Page 1 of 1

How would I get the address of a function?

Posted: Mon Mar 30, 2009 11:13 pm
by clc02
Title says most.
Unless functions are not copied when they are transfered from arguments I'm going to want to use pointers.
This is what I have now:
void doStuf() { }
void (*Ary_func[300])();;
Ary_func[0] = &void doStuf();
>.< Scratch this.
I couldn't have the () or it would call the function.

Slightly new question.
How would I tell if a function was stored at Ary_func[0]? It is stored as true but I'm not sure how to compare it Ary_func[0] != true always gets a cannot convert error.
I tried usingif(*Ary_func[0] == true) but it gets a cannot compare pointers error

Re: How would I get the address of a function?

Posted: Tue Mar 31, 2009 5:27 am
by K-Bal
You could initialize the whole array with NULL. Then you can check if(!Ary_func[0]).

Re: How would I get the address of a function?

Posted: Tue Mar 31, 2009 10:27 pm
by MarauderIIC
K-Bal wrote:You could initialize the whole array with NULL. Then you can check if(!Ary_func[0]).
Or for clarity for you,

Code: Select all

if (Ary_func[0] != NULL) {
    call it;
}
And if you output a pointer, it outputs the address. I'm not sure what this would tell you. Why do you need to output the address of a function?