在帖子中没有回答这个问题#include< filename>之间的区别是什么?和#include“文件名”?这是一个不同的问题.
我正在研究C和C之间的差异.我通过比较您可以对每种语言进行的最基本的程序来做到这一点:
在C:
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
在C.
#include <iostream>
int main()
{
std::cout << "Hello World!!!" << std::endl;
return 0;
}
我知道标题和编译过程.但我想知道C和C的#include指令之间是否有任何区别.例如,可能以不同的方式复制复制时的标题内容.
我认为这个问题非常简单,您可以通过说“不”或“是,这是差异:1),2)”来回答.
是的,至少有两个不同之处.在C(WG21 N4567 [cpp.include] / 5):
The implementation shall provide unique mappings for sequences
consisting of one or more nondigits or digits (2.10) followed by a
period (.
) and a single nondigit. The first character shall not be
a digit. The implementation may ignore distinctions of alphabetical
case.
在C(WG14 N1570 6.10.2 / 5,强调我的):
The implementation shall provide unique mappings for sequences
consisting of one or more nondigits or digits (6.4.2.1) followed by a
period (.
) and a single nondigit. The first character shall not be a
digit. The implementation may ignore distinctions of alphabetical case
and restrict the mapping to eight significant characters before the
period.
符合要求的C实现可以将“foobarbaz.h”和“foobarbat.h”映射到同一个源文件.符合C的实现不能.
另外,在C(N1570 6.4.7)中:
If the characters '
,
,"
,//
,or /*
occur in the sequence
between the <
and >
delimiters,the behavior is undefined.
Similarly,if the characters '
,or /*
occur in the
sequence between the "
delimiters,the behavior is undefined.
在C中(N4567 [lex.header] / 2):
The appearance of either of the characters '
or
or of either of
the character sequences /*
or //
in a q-char-sequence or an
h-char-sequence is conditionally-supported with implementation-defined semantics,as is the appearance of the
character "
in an h-char-sequence.
“有条件地支持实现定义的语义”意味着
>如果实施不支持,则必须发布诊断;
>如果实现确实支持它,则必须记录其对此构造的解释.
而“未定义的行为”意味着实现可以做任何想做的事情.