473,414 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

Can any one explain the function prototype -

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

Dec 29 '05 #1
3 2903

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.

Dec 29 '05 #2
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?

Dec 29 '05 #3

an*************@gmail.com 写道:
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.

Dec 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.