avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] mass stupidity with registers and longs


From: Russell Shaw
Subject: Re: [avr-gcc-list] mass stupidity with registers and longs
Date: Fri, 14 Jan 2005 17:18:47 +1100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040820 Debian/1.7.2-4

Curtis Maloney wrote:

I give up. I've been trying to shift 4 chars into an unsigned long, but can't stop GCC 3.4.1 (what's shipped with the latest WinAVR) from sign extending values, let alone producing sane code.

I've tried -Os, -O2, -O3, with and without -fnew-ra... the asm varies, but is generaly crap.

now, if I have:
    extern char a[4];
    unsigned long ul;

    ul = ( (unsigned)a[0] << 8 ) | (unsigned)a[1];

why would it be sign extending a[0] and a[1] when they're cast to unsigneds?

a[] is sign extended and the resulting integer interpreted as unsigned.

    extern char a[4];
    unsigned long ul;

    ul = ( (unsigned char)a[0] << 8) | (unsigned char)a[1];


reply via email to

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