hi, is it possible to do this in c? (as it can be done in nasm for ex.)
dd func
func:
thanks for the answer.
declare
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: declare
If you were a good C programmer like you should (You are asking it in the os development forum), you'd know the answer is yes.
Does the type void(*)(void) mean anything to you?
Does the type void(*)(void) mean anything to you?
Re: declare
To declare a variable which points to a function, declare the function prototype with the asterisk and function name enclosed in parentheses, like this:
void (*FunctionPtr)();
You can also declare arrays of function pointers like this. And by using a typedef, you can avoid having to type the function declaration over and over when using it in multiple places. For example:
void (*FunctionPtr)();
You can also declare arrays of function pointers like this. And by using a typedef, you can avoid having to type the function declaration over and over when using it in multiple places. For example:
Code: Select all
typedef int (*RqFn)(void*,WA_REPLYDATA*,CWebApCtl*,int*);
RqFn RequestFns[]={
(RqFn)RqAbort
};
Re: declare
I'd recommend not to use the cast "(RqFn)RqAbort" but plain "RqAbort" so the compiler may issue an error when RqAbort happens to be of a different prototype.Gigasoft wrote:To declare a variable which points to a function, declare the function prototype with the asterisk and function name enclosed in parentheses, like this:
void (*FunctionPtr)();
You can also declare arrays of function pointers like this. And by using a typedef, you can avoid having to type the function declaration over and over when using it in multiple places. For example:Code: Select all
typedef int (*RqFn)(void*,WA_REPLYDATA*,CWebApCtl*,int*); RqFn RequestFns[]={ (RqFn)RqAbort };
Roel
Re: declare
Well, in the program which that was taken from, each function in the table has parameters 1 and 2 pointing to different structures, as each function processes a different type of request from another application, where parameter 1 points to the request parameters and parameter 2 to the buffer which will receive the reply.
Re: declare
void (*ptr)() = &func for func with no arguments and returning void i guess, thanks for the quick answer. but there is one more thing, which i want to do with that pointer. i need to have this pointer at the exact begining of compiled code. how can i do that?
Re: declare
You don't. The exact beginning of the compiled code is probably not a function.