|
From: | David Brown |
Subject: | [avr-gcc-list] Re: Passing a string variable to lcd_puts |
Date: | Sat, 28 Mar 2009 16:21:48 +0100 |
User-agent: | Thunderbird 2.0.0.21 (Windows/20090302) |
Preston Wilson wrote:
Sorry David for the second reply to you. I intended to reply to everyone. "David VanHorn" wrote:Ok, so that leaves me VERY confused.. Correct me if I'm wrong, but "signed" variables use the high bit to indicateIn C there are 3 char types. "char" "signed char" "unsigned char" so maybe "char" isn't signed?negative by setting it to a 1, correct?So, I can only see two options, either you do, or you don't. Char has to equate to signed char, or unsigned char, doesn't it?
That's true in C, but C++ considers all three as separate types (C++ is a little bit fussier about mixing types). As a programmer, you should be much more fussy about keeping all three types separate than either C or C++ compilers.
char is either signed or unsigned. The standard leave it up to the implementation as to which is used with an unqualified "char" type. Traditionally under Unix environments a naked char type is signed, and that is what gcc uses as a default. I believe there is a compiler option that will change this behavior, but I'm too lazy to look right now.
Don't look it up - if you learn the compiler's default behaviour, you risk writing incorrect code. If it is in any way relevant whether a char is signed or not, write "signed char" or "unsigned char" explicitly in the code. The only reason one would ever use a plain "char" is to hole a true character - a letter - such as in strings. Since it is (in general) meaningless to do arithmetic on characters, it does not matter if the compiler considers them to be signed or unsigned.
[Prev in Thread] | Current Thread | [Next in Thread] |