(*(void(*)())0)();

M

mayflower

Ganga 写é“:
Can any one explain the function prototype -

( * (void ( * ) ( ) ) 0 ) ( );

typedef void (*function_ptr) ();
// function_ptr is a pointer to functions without parameter and return
value

function_ptr pZero = (function_ptr) 0;
// convert 0 to function_ptr

(*pZero)();
// call the function which is pointed by pZero
// that is, call the function whose address is 0.
 
A

anujanujdhamija

I understand that statement function_ptr pZero = (function_ptr) 0;
initializes the pointer to 0 just the way non-function pointers are
initialized to NULL.

But wont a call using zero initialized function pointer as in
(*pZero)() cause program to crash?
 
M

mayflower

(e-mail address removed) 写é“:
I understand that statement function_ptr pZero = (function_ptr) 0;
initializes the pointer to 0 just the way non-function pointers are
initialized to NULL.

But wont a call using zero initialized function pointer as in
(*pZero)() cause program to crash?

Yes. I cannot remember it exactly, but I think I saw it in <<C Traps
and Pitfalls>>.

The author take this example to show how the function pointer works.
And the example came from a real project, in which a routine at
*ADDRESS 0*
needs be called when the system startup. However, the example is very
special.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top