[Top][All Lists]

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

Re: [avr-gcc-list] long character constants like 'abcd'.. - (('a' << 24)

From: Matthias Ringwald
Subject: Re: [avr-gcc-list] long character constants like 'abcd'.. - (('a' << 24) | ('b' << 16) | ('c' << 8) | 'd') doesn't work
Date: Wed, 22 Jan 2003 10:14:06 +0100

Some of you (and myself to..) suggested the following to get the 32 bit const.

On Mittwoch, Januar 22, 2003, at 08:43  Uhr, Egil Kvaleberg wrote:
What are you trying to do? If you want to place 4 ASCII bytes in a 32
bit word, then do:

        (('a' << 24) | ('b' << 16) | ('c' << 8) | 'd')

I just tried it, and avr-gcc tells me:
../share/sits-features.c:357: warning: left shift count >= width of type
../share/sits-features.c:357: warning: left shift count >= width of type

and the assembler code shows, that this is wrong. It would work for 16 bit consts.

        ldi r22,lo8(25444)
        ldi r23,hi8(25444)
        ldi r24,hlo8(25444)
        ldi r25,hhi8(25444)

to get it correctly I have to use

((u32) 'a' << 24) | ((u32) 'b' << 16) | ((u32) 'c' << 8) | (u32)'d')

and the assembler code is fine.

Traditionally (as in K&R), 'ab' was technically a legal presentation for
(('a' << 8) | 'b') or (('b' << 8) | 'a').
So I'm just an old K&R person.. :)

 The actual byte sequence was
up to the compiler, which made the feature simply to esoteric. Four
character constants was also supported.

It may have disappeared altogether in later C variants.
It is still around.

Thanks for this info,

Matthias Ringwald

avr-gcc-list at http://avr1.org

reply via email to

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