- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
编译以下代码片段时,gcc 和 clang 都只发出警告。注意 int
旁边的 \
之后的空格:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int \
a = 10;
printf("%d\n", a);
}
海湾合作委员会:
main.c:7:6: warning: backslash and newline separated by space [enabled by default]
clang :
main.c:7:7: warning: backslash and newline separated by space int ^
在 5.1.1.2 的 c99 标准中它说:
Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.
为什么C编译器不符合这里的C标准?我认为这只是他们的创作者决定不这样做。我在 gcc 邮件列表上发现了一条消息,我认为它引入了这种行为:http://gcc.gnu.org/ml/gcc-patches/2000-09/msg00430.html .在那里,他们说这样做是因为尾随空格很常见,他们不想将它们视为错误。这有多普遍?
最佳答案
编译器被允许扩展语言,只要记录 gcc
在其文档中的 6.21 Slightly Looser Rules for Escaped Newlines 部分所做的更改。 .
Recently, the preprocessor has relaxed its treatment of escaped newlines. Previously, the newline had to immediately follow a backslash. The current implementation allows whitespace in the form of spaces, horizontal and vertical tabs, and form feeds between the backslash and the subsequent newline. The preprocessor issues a warning, but treats it as a valid escaped newline and combines the two lines to form a single logical line. This works within comments and tokens, as well as between tokens. Comments are not treated as whitespace for the purposes of this relaxation, since they have not yet been replaced with spaces.
和clang
strives to support gcc
扩展并指向关于它们的 gcc
文档:
this document describes the language extensions provided by Clang. In addition to the language extensions listed here, Clang aims to support a broad range of GCC extensions. Please see the GCC manual for more information on these extensions.
因此,他们履行了与标准相关的义务。事实上Linux depends on many gcc extensions .我们可以通过查看 C99 标准草案部分 4.
Conformance 段落 6 看到这一点,其中说:
[...]A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.3)
脚注 3 说:
This implies that a conforming implementation reserves no identifiers other than those explicitly reserved in this International Standard.
和第 8 段:
An implementation shall be accompanied by a document that defines all implementation defined and locale-specific characteristics and all extensions.
gcc
还记录了您可以使用 -pedantic
标志来 generate a warning when using extensions您可以使用 -pedantic-errors
标志使其成为错误:
[...] to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings).
关于c - 如果 C 标准说禁止使用空格,为什么 clang 和 gcc 只在反斜杠后有空格时发出警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21635063/
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的 Angular 被徽章覆盖 - 我的问题不适用,如果是这样的话: 这是信息框及其边 Angular 的 (s)css 部分(还有更多
是否可以在纯 html/css 中创建类似下面的内容? 我想做这个响应式和全 (100%) 宽度(最大左 Angular 100 像素,右边最小 50 像素,类似的东西)。 最佳答案 您可以通过转换(
如何在 fabricjs 文本中为文本提供渐变或斜 Angular 效果?? http://fabricjs.com/fabric-intro-part-2/ 这里给出了形状和所有示例,我将其与文本绑
我用过: http://apps.eky.hk/css-triangle-generator/ 为彼此对 Angular 放置的两个不等边三 Angular 形生成 css: 左下三 Angular
我是一名优秀的程序员,十分优秀!