本文介绍了GCC编译器选项-wno-四个字符常量和-wno-multichar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-Wno-四个字符常量上找不到任何文档,但是我怀疑它与 -Wno-multichar类似。我是正确的吗?

Couldn't find any documentation on -Wno-four-char-constants, however I suspect that it is similar to -Wno-multichar. Am I correct?

推荐答案

它们是相关的但不是同一件事。

They're related but not the same thing.

使用 -Wall --pedantic 标志进行编译,分配:

Compiling with the -Wall --pedantic flags, the assignment:

int i = 'abc';

产生:

同时具有GCC和CLANG,而:

with both GCC and CLANG, while:

 int i = 'abcd';

产生:

CLANG警告:多字符常量[-Wfour-char-constants]

CLANG warning: multi-character character constant [-Wfour-char-constants]






标准(包括带有勘误 TC1,TC2和TC3的C99标准,第6.4.4.4小节-字符常量)指出:


The standard (C99 standard with corrigenda TC1, TC2 and TC3 included, subsection 6.4.4.4 - character constants) states that:

多字符始终解析为 int ,但是由于将字符打包成一个 int 的顺序为如果未指定,则很难移植使用多字符常量(确切的值是取决于实现的)。

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).

编译器的不同之处也在于它们处理不完整的多字符(例如 'abc')。

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).

可以接受完整多字符的可移植性问题的人可能仍然想要警告不完整的多字符( -Wmultichar -Won-四个字符常量)。

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).

这篇关于GCC编译器选项-wno-四个字符常量和-wno-multichar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:34