proposal: warning for incomplete multichars
Mon Oct 3 14:02:00 GMT 2011
This concerns multiple character integer constants, e.g.
as discussed in the C99 standard in subsection 184.108.40.206.
We'll call them "multichars".
First: everybody agrees multichars are non-portable and therefore to
That said, there are real-life situations where they are very natural.
People use them, portability notwithstanding.
Presently cpp has options to turn all multichar warnings on, or all
off. Furthermore, it properly warns of multichars that are too big
for the int type. This is good.
An edge case is that of *incomplete* multichars, such as
While gcc arranges for this to equal '\0abc' as one might expect (and
as in many applications is assumed); other compilers do not. The C99
standard is silent on the point.
(Note this behavior is independent of endian-ness.)
The primary issue with complete multichars is that of endian-ness, but
that can be handled in various programmatic ways.
Incomplete multichars by contrast are impossible to detect
programmatically and are non-portable even between compilers on the
same architecture. Furthermore, in many applications, a multichar
with other than four characters is always a typo.
What is meant by an incomplete multichar depends: on a 64-bit
architecture, an int isn't completely specified by four characters
(without a specification of padding and endian-ness). Also, there are
applications too where two-character multichars are always intended.
I propose therefore a default warning of an incomplete multichar, to
compliment the existing option -Wno-multichar, to be turned on by an
option something like
where <n> is 2, 4, or 8, which would turn on warnings for any
multichar of length besides <n> bytes.
More information about the Gcc