How would I get the address of a function?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
clc02
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 7
Joined: Sun Mar 22, 2009 9:55 pm

How would I get the address of a function?

Post 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
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

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

Post by K-Bal »

You could initialize the whole array with NULL. Then you can check if(!Ary_func[0]).
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

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

Post 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?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply