为什么三字母组合产生了现代C ++编译器错误? [英] Why are trigraphs generating errors in modern C++ compilers?

查看:163
本文介绍了为什么三字母组合产生了现代C ++编译器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使在GCC编译器,三字母都没有得到编译时没有明确指定的三字符属性。

Even in the GCC Compilers, the trigraphs are not getting compiled without explicitly specifying the trigraph attribute.

#include<stdio.h>

int main()
 {
 int a=4;
 if((a==4) ??! (a==5))
   printf("\nHello world!");
 return 0;
 }

另存为try.c这个程序在编译器GCC编译得到,只有当我们指定的gcc -Wall -trigraphs try.c 键,它仍然显示警告。
你可以招募一些编译器将对待和处理三字母没有任何错误或警告?

This program saved as try.c gets compiled in GCC Compiler only when we specify gcc -Wall -trigraphs try.c and it still shows warnings. Can you enlist some compilers that will treat and handle trigraphs without any errors or warnings?

推荐答案

三字母由1989年的ANSI C标准出台,并保留在其随后所有的C类标准。他们还出现在第一个ISO C ++标准,于1998年出版,并在以后所有的C ++标准达到C ++ 14。 (三字母将在C ++ 17。感谢乔纳森·莱弗勒和DYP对跟踪的细节被删除。)

Trigraphs were introduced by the 1989 ANSI C standard, and are retained in all later C standards. They also appear in the first ISO C++ standard, published in 1998, and in all later C++ standards up to C++14. (Trigraphs will be removed in C++17. Thanks to Jonathan Leffler and dyp for tracking down the details.)

他们不是在任何语言中的可选功能;所有标准的编译器的由各自的语言标准规定必须的支持他们,跨preT他们。

They are not an optional feature in either language; all conforming compilers must support them and interpret them as specified by the respective language standard.

例如,如果此程序:

#include <stdio.h>
int main(void) {
    if ('|' == '??!') {
        puts("ok");
    }
    else {
        puts("oops");
    }
    return 0;
}

打印哎呀,那么你的编译器是不符合要求的。

prints oops, then your compiler is non-conforming.

但许多,也许是大多数C编译器不完全符合默认。只要一个编译器可以制成以符合某种方式的标准,这是足够好的至于标准而言。 (gcc,需要 -pedantic -std = ... 来做到这一点。)

But many, perhaps most, C compilers are not fully conforming by default. As long as a compiler can be made to conform to the standard in some way, that's good enough as far as the standard is concerned. (gcc requires -pedantic and -std=... to do this.)

不过,即使一个编译器完全符合要求,没有什么的,从警告不谈它喜欢的禁止编译器的标准。标准的C编译器必须诊断的语法规则或约束违反,但它喜欢它可以发出许多额外的警告 - 它不一定需要诊断和警告等区分

But even if a compiler is fully conforming, there's nothing in the standard that forbids a compiler from warning about anything it likes. A conforming C compiler must diagnose any violation of a syntax rule or constraint, but it can issue as many additional warnings as it likes -- and it needn't distinguish between required diagnostics and other warnings.

三字母很少被用到。绝大多数开发系统直接支持所有的字符其三字母代替: [ \\ ] ^ { | }

Trigraphs are very rarely used. The vast majority of development systems support directly all the characters for which trigraphs substitute: #, [, \, ], ^, {, |, }, ~.

事实上,很可能是三字母使用的偶然的往往比他们正确的:

In fact, it's likely that trigraphs are used accidentally more often than they're used correctly:

fprintf(stderr, "What just happened here??!\n");

警告有关可能改变一个程序(相对于这意味着如果语言没有三字母那就得)的含义三字母不但由ISO标准,恕我直言,完全合理的许可。大多数编译器可能有选项关闭这样的警告。

Warning about trigraphs that might alter the meaning of a program (relative to the meaning it would have if the language didn't have trigraphs) is both permitted by the ISO standard and IMHO perfectly reasonable. Most compilers probably have options to turn off such warnings.

相反,对于一个C ++编译器17的的实施三字母,这将是合理的警告,将已在C ++ 14或更早版本被视为三字母组合序列。再次,禁止这种警告的选项将是一个很好的事情。

Conversely, for a C++17 compiler that doesn't implement trigraphs, it would be reasonable to warn about sequences that would have been treated as trigraphs in C++14 or earlier. Again, an option to disable such warnings would be a good thing.

这篇关于为什么三字母组合产生了现代C ++编译器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆