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

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

Re: [avr-gcc-list] New GCC warning - how to silence?


From: Dave Hansen
Subject: Re: [avr-gcc-list] New GCC warning - how to silence?
Date: Mon, 09 Apr 2007 10:43:55 -0400

From: Bob Paddock <address@hidden>
[...]
What I've never understood at all is why are characters signed
in any case?    What exactly is the meaning of a negative-letter-"A"?


It's all hysterical raisins.

The earliest C compilers made char signed by default because ASCII only requires 7 bits, and signed operations on 8-bit values on the target platforms were less expensive than unsigned.

As C proliferated before there was a standard, many compilers followed the practice, even if there was no difference between signed and unsigned operations. However, if unsigned operations were less expensive, many compilers made char unsigned by default.

When the C standards committee met, one of their charters was to codify existing practice. Since both signed and unsigned plain char were in common use at the time, the committee allowed either, so long as an implementation defined which it used.

IMHO this was an error on the committee's part. As it is, the plain char type is almost useless, but you're essentially required to use it, since, for example, string literals point to arrays of plain char. Furthermore, combined with the new (with the original standard) "value preserving" automatic promotion rules, signed char types are the source of many confusing promotion errors.

As it is, we're stuck with it, and since avrgcc has used signed chars by default for many years, the only reason to change to unsigned would be code efficiency gains, i.e., if operations on unsigned char were much less expensive than operations on signed char. I haven't looked into it deeply, but I don't think that's the case for the AVR architecture.

It would be better to code to stdint.h, than
rely on any ambiguous compiler switches/standard-C 'undefined' issues.

For applications written for an 8-bit micro, such as the AVR, where you want tight control on such things, this is true. It is not true for all applications that might be written in C, however. And you really have no choice when it comes to using the standard library or string literals: you're stuck with plain char for those.

Regards,

  -=Dave

_________________________________________________________________
MSN is giving away a trip to Vegas to see Elton John.  Enter to win today. http://msnconcertcontest.com?icid-nceltontagline





reply via email to

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