- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
就这个问题而言,我只对符合标准的 C++ 感兴趣,而不是 C 或 C++0x,也不对任何特定于实现的细节感兴趣。
Questions不时出现关于#include ""
之间的差异和 #include <>
.该论点通常归结为两个差异:
#include <>
用于“标题”,而 #include ""
用于“源文件”。以下是相关引用:ISO/IEC 14882:2003(E)
16.2 Source file inclusion [cpp.include]
1 A #include directive shall identify a header or source file that can be processed by the implementation.
2 A preprocessing directive of the form
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.# include < h-char-sequence > new-line
3 A preprocessing directive of the form
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read# include "q-char-sequence" new-line
with the identical contained sequence (including > characters, if any) from the original directive.# include < h-char-sequence > new-line
(上面引用的重点是我的。)这种差异的含义似乎是标准打算区分“标题”和“源文件”,但该文档没有定义这些术语或它们之间的区别。
很少有其他地方甚至提到头文件或源文件。一些:
158) A header is not necessarily a source file, nor are the sequences delimited by in header names necessarily valid source file names (16.2).
似乎暗示头文件可能不驻留在文件系统中,但也没有说源文件存在。
2 Lexical conventions [lex]
1 The text of the program is kept in units called source files in this International Standard. A source file together with all the headers (17.4.1.2) and source files included (16.2) via the preprocessing directive
#include
, less any source lines skipped by any of the conditional inclusion (16.1) preprocessing directives, is called a translation unit. [Note: a C + + program need not all be translated at the same time. ]
这是我能找到的最接近定义的,它似乎暗示标题不是“程序的文本”。但是如果你 #include
一个标题,它不会成为程序文本的一部分吗?这有点误导。
那么什么是标题?什么是源文件?
最佳答案
我的阅读是标准标题,包括使用 <>
尖括号,不必是文件系统上的实际文件;例如一个实现可以自由地启用一组提供 iostream
功能的“内置”操作。当它看到 #include <iostream>
.
另一方面,#include "xxx.h"
中包含的“源文件”旨在成为驻留在文件系统上的文字文件,以某种依赖于实现的方式进行搜索。
编辑:为了回答您的具体问题,我相信“标题”仅限于 #include
标准中规定的能力设施:iostream
, vector
和 friend ——或者作为标准的扩展来实现。 “源文件”可以是程序员可以编写或使用的任何非标准工具(如 .h
文件等)。
关于c++ - Pedantic : What Is A Source File? 什么是 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3469588/
这个 GCC 警告是什么意思? cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used 相关行是: __attribute
我刚刚开始学习 C 作为一种爱好。我正在用“C 编程:一种现代方法”一书来做这件事。那里有一个名为 pun.c 的第一个程序。这是代码: #include int main(void) { in
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html : Some users try to use -Wpedantic to check
我们需要这样使用gcc编译C源代码: gcc -ansi -pedantic -Wall program.c 我想知道如何“自动化”这个,所以当我输入时: gcc program.c 它将自动编译 3
就这个问题而言,我只对符合标准的 C++ 感兴趣,而不是 C 或 C++0x,也不对任何特定于实现的细节感兴趣。 Questions不时出现关于#include ""之间的差异和 #include <
我正在使用 Clang v3.7.0 和 Mingw-w64 5.1.0 和 GCC 5.1.0,全部 64 位,在 Windows 10 上。我的目标是使用一组 Clang 和 GCC 选项,这将使
我想知道是否有等效于 int64_t在 C 中可以在 32 位和 64 位平台上运行,并且符合 ansi 和 pedantic gcc 模式。 我发现这很有趣 post ,但它与 C++ 相关。 我试
我刚刚深入研究 gcc 手册,有些事情我仍然不清楚: 指定 std 时,我应该始终结合使用 -pedantic 吗? 使用 -g 时,标准级别就足够了,或者我应该指定级别 3,即-g3? 使用 -We
我正在尝试从其他地方(特别是 here )获取一些代码,以便在 gcc 被赋予 -pedantic 标志时没有任何警告地进行编译。唯一的问题是这段代码: struct __attribute__ ((
我有一个带有复制构造函数和采用 std::reference_wrapper 的构造函数的类: #include #include class Class { public: Class(
我的代码中某处有这个 lambda: [](bool a, bool=true){ return !a;} } 和 GCC 4.6“提示”这个警告: warning: default argument
This note说: -ansi: tells the compiler to implement the ANSI language option. This turnsoff certain "
无法使用 -Wall -pedantic -ansi 标志在 Windows 上的 Visual Studio Code 终端上执行程序。现在的赋值程序只是一个简单的 C 语言“Hello World
我尝试从模板制作一个 makefile,这就是我得到的: CFLAGS = -Wall -pedantic LFLAGS = -lpthread CC = gcc OBJS = bank5.o cli
这是一个简单的 C 文件: #include #include int main() { printf("hi there!\n"); return 0; } 使用 gcc -an
在 linux 上,我使用这些标志与 gcc 一起编译 CFLAGS=-Wall -pedantic -g -Wextra -pthread 我在 VS 中有哪些选项可以启用类似的标志?额外警告等 最
我目前正在使用 GCC-5.3 在我的机器上运行 Linux Mint,因为默认包含 C11。 我开始为自己学习 C 只是为了好玩,如果我没记错的话,当时的 GCC 版本是 4.8。 如果在以下程序中
我正在编译 C++ 代码,我想启用 -pedantic 选项。 我正在使用 GCC 4.0,在 Mac OS X Leopard 上运行 Xcode。 例如,可以允许可变参数宏和 long long使
我正在使用 Eclipse 编写 C/C++ 程序。我想使用 -Wall 和 -pedantic 标志编译我的代码。如何在 Eclipse 中启用这些标志,以便在编译 C/C++ 程序时默认使用它们?
我主要使用 GCC 来开发我的库,但我想尽可能确保交叉编译器兼容性,尤其是标准一致性。为此,我在命令行中添加了几个 -W... 标志。我还会添加 -pedantic,但我对它关于 long long
我是一名优秀的程序员,十分优秀!