On Fri, Nov 10, 2006 at 02:32:10PM -0800, Howard Chu wrote:
> 
> With the previous example, if alias1.c was instead:
> 
> ####
> #include <stdio.h>
> 
> extern void getit( void **arg );
> 
> main() {
>        union {
>                int *foo;
>                void *bar;
>        } u;
> 
>        getit( &u.bar );
>        printf("foo: %x\n", *u.foo);
> }
> ####
> 
> gcc no longer complains, but according to the spec, the code is not any 
> more reliable.

   As far as I know, memcpy() is the answer:

#include <stdio.h>
#include <string.h>

extern void getit (void **arg);

int main ()
{
        int *foo;
        void *bar;

        getit (&bar);
        memcpy (&foo, &bar, sizeof (foo));
        printf ("foo: %x\n", *foo);
        return (0);
}

-- 
Rask Ingemann Lambertsen

Reply via email to