> appro> > The function pointer *must* be inside a data object to make
> appro> > such constructs legal,
>
> appro> But that's what Richard (subconsciously?) attempted to do in
> appro> first place:
>
> Don't look at me, that part of the code was there in mem.c since
> eons...
Sorry:-) I should have written "whomever who wrote this."
>
> void (*mem_callback)()=(void (*)())cb;
> ...........................................^
> %CC-I-NONSTANDCAST, In the initializer for mem_callback, "cb" of type "pointer to
>char", is being converted to "pointer to function () returning void". Such a cast is
>not permitted by the standard.
>
> As you can see, whatever you do with the current scheme, there will
> always be a conversion between function pointers and non-function
> pointers.
>
> appro> > so this is not silly at all. An alternative would be to use
> appro> > unions of a function pointer
> appro> Why structures/unions? "lh_doall_arg(mh,(void (*)())cb_leak,(void
> appro> *)&mem_cb)" should do...
Look at it more carefully. I don't cast pointer to function, but a
pointer to pointer to function, which is perfectly
portable/legal/legitimate/valid/compliant-with-standard/whatever.
>
> The easiest way to avoid the conversions noted above is to have a
> union like this:
>
> union foo {
> void *simple;
> int (*fn)();
> };
>
> and use it internally. You put whatever char * you want to convert to
> a functino pointer into simple and pull out the function pointer from
> fn, and vice versa.
Just to make it clear. Are you going to pass the union by reference of
by value? You have to pass by reference which is equivalent to what I
proposed, but without unions. Passing by value would be wrong and
compiler should complain.
>
> appro> And I fail to understand why mem_cb has to be declared static?
>
> Not to be seen outside of the file?
The sentence was rather I don't understand why it has to be declared
*outside* CRYPTO_mem_leaks_cb scope. And that's what stands in the next
one:
> appro> It can be perfectly declared in CRYPTO_mem_leaks_cb scope which
> appro> also makes it multi-thead safe, doesn't it?
>
> appro> typedef void (*cb_t) ();
> appro>
> appro> static void cb_leak(MEM *m, void *cb)
> appro> {
> appro> void (*mem_callback)()=*((cb_t *)cb);
>
> You convert from void * to void (*)() (i.e. between a "simple
> type" and a function pointer).
Nope, it's cast from a void pointer to pointer to pointer to function
and fetch.
> DEC C will complain.
Shall we bet:-)
Andy.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]