First of all, new_func
is not a function, it's a function pointer.
The code snippet that you have shown in your question is casting an int
value to a function pointer of type void (*)(int, int)
and assigning it to new_func
:
new_func = (void (*)(int, int)) entry;
but you haven't mentioned what argument is passed to entry
parameter of function()
function.
Are you type casting a function pointer to int
and passing it as first argument to function function()
?
Your program can either have implementation defined behaviour or undefined behaviour depending on value of first argument passed function()
function.
From C11#6.3.2.3p5
5 An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation.67)
From C11#6.3.2.3p6
6 Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. If the result cannot be represented in the integer type, the behavior is undefined. The result need not be in the range of values of any integer type.