问题
Couldn't find any documentation on -Wno-four-char-constants
, however I suspect that it is similar to -Wno-multichar
. Am I correct?
回答1:
They're related but not the same thing.
Compiling with the -Wall --pedantic
flags, the assignment:
int i = 'abc';
produces:
warning: multi-character character constant [-Wmultichar]
with both GCC and CLANG, while:
int i = 'abcd';
produces:
GCC warning: multi-character character constant [-Wmultichar]
CLANG warning: multi-character character constant [-Wfour-char-constants]
The standard (C99 standard with corrigenda TC1, TC2 and TC3 included, subsection 6.4.4.4 - character constants) states that:
The value of an integer character constant containing more than one character (e.g.,
'ab'
), [...] is implementation-defined.
A multi-char always resolves to an int
but, since the order in which the characters are packed into one int
is not specified, portable use of multi-character constants is difficult (the exact value is implementation-dependent).
Also compilers differ in how they handle incomplete multi-chars (such as 'abc'
).
Some compilers pad on the left, some on the right, regardless of endian-ness (some compilers may not pad at all).
Someone who can accept the portability problems of a complete multi-char may anyway want a warning for an incomplete one (-Wmultichar -Wno-four-char-constants
).
来源:https://stackoverflow.com/questions/47304722/gcc-compiler-options-wno-four-char-constants-and-wno-multichar