[Top][All Lists]

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

Re: [avr-gcc-list] long character constants like 'abcd'

From: E. Weddington
Subject: Re: [avr-gcc-list] long character constants like 'abcd'
Date: Tue, 21 Jan 2003 14:16:20 -0700

On 21 Jan 2003 at 20:33, Matthias Ringwald wrote:

> hi
> I stumbled about a problem using avr-gcc (avr-gcc (GCC) 3.3 20020918
> (experimental), here for atmega128)
> I tried using 32 bit ids to address attribute/value pairs in the
> eeprom. But I failed to do something like this in my app:
> u32 myID = 'abcd';
> Obviously, 4 characters make up a 32 bit number as it does on other
> platforms..
> Here, I get a warning from the compiler saying e.g.
> ../share/sits-features.c:358:27: warning: character constant too long
> for its type
> I'm wondering if this must be as I could easily write
> u32 myID = 0x12345678;
> without problems.
> Or is there another way to specify such a value ?
> (a << 24 | b << 16  .... etc fails also..)

What are you trying to do?

u32 is a 32 bit number type. Whenever you enclose one character in 
single quotes it is of type char. Thus 'abcd' does not even make 
sense as a character type. And it certainly doesn't represent a 
number which you are trying to assign to a variable of type u32.

When you used 0x12345678, *that* represents a number. 'a' represents 
the ASCII code 97 which corresponds to the lowercase a. "abcd" is a 
string of characters with an implied null at the end of the string. 
'abcd' is meaningless as a constant. 

You can write 

u32 myID = 0xabcd;

But that would only be a 16 bit numerical constant.


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

reply via email to

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