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: David Brown
Subject: Re: [avr-gcc-list] New GCC warning - how to silence?
Date: Tue, 10 Apr 2007 09:19:05 +0200
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Joerg Wunsch wrote:

The issue is, any implementation will always have to implement it as
either

unsigned char == char != signed char

or

unsigned char != char == signed char.

Yet, as the default signedness of char is not defined by the standard,
any *portable* application has to be written as if

unsigned char != char != signed char

That's the entire point the warning is about, and that's why neither
your compile-time option nor your suggested change to the compiler's
default behaviour would avoid the warning.  Nor would they fix the
broken (in terms of portability) application.


I agree with most of this. It is more natural for most processors (small ones, anyway) to process chars as unsigned - sometimes comparisons with unsigned data are smaller and faster than with signed data (though not on the AVR). Thus I explicitly use the "-funsigned-char" flag for all my targets. But well-written C code *should* make the distinction between "char", which represents a character, and "unsigned char" and "signed char", which are the smallest unsigned and signed integer types. They are different types, used for different purposes.

Anyone switching to a significantly new version of their compiler tools should expect that some things may change. In this case, the compiler is now fussier about mixing the signedness of chars, and issues warnings. The developer has three choices - they can stick to the older version of the compiler (which is normally the advisable thing to do with existing projects), they can turn off that specific warning (this is *exactly* why there are command-line options for disabling individual warnings), or they can correct their code.

It's important not to change the default "char" signedness - people *do* write code that uses "char" as a small signed integer. They are writing bad code when they do so, but it is done nonetheless. If it is to be changed, then it has to be done over two major versions, with current releases noting that "char" will change to unsigned in the future. That at least gives people fair warning - just as is done when introducing any other incompatible changes.

mvh.,

David





reply via email to

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