Re: Global restricted function pointer



Jacob Shamalini wrote:
) I have a trampoline variable into which I repeatedly load callbacks
) for execution, I'd like to be hopeful about it getting optimized into
) a register.
)
) More or less like this:
)
) void (*current_callback)();
)
) void run()
) {
) for(;;)
) current_callback(); // each callback loads a new callback as a
) side effect
) }
)
)
) I _can_ declare a global restricted object pointer, therefore I wonder
) if a function pointer might be legal.

I don't think 'restrict' does what you think it does.
And even if it did, you do *not* want it optimized into a register,
otherwise it could be calling the wrong function.

If you *want* it to be a register instead of a global pointer,
the following method could be useful:

void run()
{
void *(* cb)();
cb = init;
while (cb)
cb = cb();
}

I.E. each callback returns the next callback instead of
setting it in a global.

Note: the type definition of cb becomes quite tricky in this case,
so I decided to let the functions return void pointers which get
autoconverted to the correct function type by the assignment.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
.



Relevant Pages

  • Re: [RFC] timers, pointers to functions and type safety
    ... * they have callback of type void ... callback is called by the code that even in theory has no ... cast to unsigned long and cast back in the callback. ... number - not a pointer cast to unsigned long, not an index in array, etc. ...
    (Linux-Kernel)
  • Re: function pointer help!
    ... //the return void and input prameters are defined in the manual... ... void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*) ... You are attempting to use a C++ member function as the callback, but the callback is defined in terms or C, not C++. ... The underlying problem is that C++ functions receive a hidden parameter, the 'this' pointer, so their signature is incompatible with C definitions. ...
    (microsoft.public.vc.mfc)
  • Re: legality of signature changes of callback functions
    ... Suppose that some type of callback function is declared ... to take a pointer to some struct as one of its argument. ... taking a void* for this argument. ... converts it to a Something* to add type information. ...
    (comp.lang.c)
  • Re: Custom filter
    ... You expect a function pointer so better be safe and tell the ... STDMETHODIMP CPrintPressFilter::Setcallback(void* Callback) ... public delegate void MyCallback; ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: The usage of %p in C
    ... could fail even if both pointer types have the same size. ... the same manner (same register, same stack location, same memory ... So failure to include a prototype for mallocand using the cast: ... passing anything other than pointer to void to printf ...
    (comp.lang.c)