Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Grum

Stupid question

Recommended Posts

set_window_handler (chat_win, ELW_HANDLER_DISPLAY, &display_chat_handler);

Ok, a stupid question, but it's been bugging me: why &display_chat_handler, and is it even correct? I'd think that display_chat_handler by itself is by definition an address, and that the only reason it works is that & on a fixed address returns the address itself. Is that correct, or am I missing something?

 

[NOTE: the line above I added myself, but it's analogous to other calls to set_window_handler () in the code]

Share this post


Link to post
Share on other sites

I believe, if my memory of K&R's "The C Programming Language" is correct, is that a function is represented as the same way as a normal variable, ie. the name representing the function, parens only used for calls. Because of this identical representation, we use & on our function/pseudo-variable to return the address.

Share this post


Link to post
Share on other sites
I believe, if my memory of K&R's "The C Programming Language" is correct, is that a function is represented as the same way as a normal variable, ie. the name representing the function, parens only used for calls. Because of this identical representation, we use & on our function/pseudo-variable to return the address.

Erm, then what do you use the name without () or & for? Assigning a value to the function? :unsure:

Share this post


Link to post
Share on other sites

void *set_window_handler(int win_id, int handler_id, int (*handler)() );

 

So you can use both declarations. As you say functions are already memory addresses - the memory address is even absolute; hereby follows that &window_handler == window_handler. :unsure:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×