GCC Compiler options -wno-four-char-constants and -wno-multichar

試著忘記壹切 提交于 2020-01-23 11:48:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!