This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

proposal: warning for incomplete multichars


Hi!

This concerns multiple character integer constants, e.g.
	'abcd'
as discussed in the C99 standard in subsection 6.4.4.4.
We'll call them "multichars".

First:  everybody agrees multichars are non-portable and therefore to
be avoided.
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
	'abc'
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
	-Wmultichar-besides=<n>
where <n> is 2, 4, or 8, which would turn on warnings for any
multichar of length besides <n> bytes.


Cheers!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]