chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] More on aliasing.


From: Peter Keller
Subject: Re: [Chicken-users] More on aliasing.
Date: Fri, 5 Jul 2002 11:29:49 -0500
User-agent: Mutt/1.2i

On Fri, Jul 05, 2002 at 10:28:37AM -0500, Peter Keller wrote:
> The real way to do the above would be to pass it in a union:
> 
> union qux { long long feh; };

> void foo(union qux bar)
> {
>       char *qux = &bar.feh;
>       unsigned int upper, lower;
> 
>       /* suppose 8 byte long */
> 
>       upper = *(unsigned int*)&char[0];
>       lower = *(unsigned int*)&char[4];
> }

Ack! I made a mistake in the above. The above as it stands isn't legal code.

union qux { 
        char fro[sizeof(long long)];
        long long feh; 
};

void foo(union qux bar)
{
        unsigned int upper, lower;

        /* suppose 8 byte long */

        upper = *(unsigned int*)&bar.fro[0];
        lower = *(unsigned int*)&bar.fro[4];
}

There we go, that's a little better. Of course the above code makes all sorts
of assumptions about the size of int and long long, most notably that long long
is twice the width of an int.

Do you(felix) ever do anything where a C_word is holding the value of a void*
or something like that? like this:

void *foo;
C_word i;

i = (C_word)foo;

Thanks.

-pete



reply via email to

[Prev in Thread] Current Thread [Next in Thread]