I came across the following code in a .cpp file. I do not understand the construct or syntax which involves the header files. I do recognize that these particular header files relate to Android NDK. But, I think the question is a general question about C++ syntax. These appear to be preprocessor commands in some way because they begin with "#". But, they are not the typical #include, #pragma, #ifndef, #define, etc. commands. The source file has more 1000+ such occurrences referencing hundreds of different .h, .c, .cpp files.
我在.cpp文件中遇到了以下代码。我不理解涉及头文件的构造或语法。我确实认识到这些特定的头文件与Android NDK有关。但是,我认为这个问题是关于C ++语法的一般性问题。这些似乎是以某种方式的预处理器命令,因为它们以“#”开头。但是,它们不是典型的#include,#pragma,#ifnf,#define等命令。源文件有1000多个这样的事件,引用了数百个不同的.h,.c,.cpp文件。
typedef int __time_t;
typedef int __timer_t;
# 116 "/home/usr/download/android-ndk-r8b/platforms/android-3/arch-arm/usr/include/machine/_types.h"
# 41 "/home/usr/download/android-ndk-r8b/platforms/android-3/arch-arm/usr/include/sys/_types.h" 2
# 33 "/home/usr/download/android-ndk-r8b/platforms/android-3/arch-arm/usr/include/stdint.h" 2
# 48 "/home/usr/download/android-ndk-r8b/platforms/android-3/arch-arm/usr/include/stdint.h"
typedef __int8_t int8_t;
typedef __uint8_t uint8_t;
The compiler (GCC) does not appear to be throwing any error related to these lines. But, I would like to understand their purpose and function. Can anybody explain these?
编译器(GCC)似乎没有抛出与这些行相关的任何错误。但是,我想了解他们的目的和功能。任何人都可以解释这些吗?
3 个解决方案
#1
18
This is output from the GCC preprocessor. Those lines are known as linemarkers. They have the syntax:
这是GCC预处理器的输出。这些行被称为行标记。他们有语法:
# linenum filename flags
They are interpreted as saying that the following line has come from the line linenum
from filename
. They basically just help you and the compiler see where lines were included from. The flags provide some more information:
他们被解释为说以下行来自文件名的line linenum。它们基本上只是帮助您和编译器查看包含行的位置。标志提供了更多信息:
1
- This indicates the start of a new file.1 - 这表示新文件的开始。
2
- This indicates returning to a file (after having included another file).2 - 这表示返回文件(包含另一个文件后)。
3
- This indicates that the following text comes from a system header file, so certain warnings should be suppressed.3 - 这表示以下文本来自系统头文件,因此应禁止某些警告。
4
- This indicates that the following text should be treated as being wrapped in an implicitextern "C"
block.4 - 这表示以下文本应被视为包含在隐式extern“C”块中。
You can see this output from preprocessing your own programs if you give the -E
flag to g++.
如果给g ++提供-E标志,则可以通过预处理自己的程序来查看此输出。
#2
2
You'll typically see lines like that in the output of the preprocessor (i.e., you normally shouldn't be seeing them at all).
您通常会在预处理器的输出中看到类似的行(即,您通常根本不应该看到它们)。
They're similar to the standard #line
directive, which has the form:
它们类似于标准的#line指令,其形式如下:
#line 42
or
#line 42 "foo.c"
which the compiler uses to control the contents of error messages.
编译器用来控制错误消息的内容。
Without the word line
, this:
没有字线,这个:
# 42 "foo.c"
is technically a non-directive (which, just to add to the fun, is a kind of directive). It's essentially a comment as far as the C standard is concerned. At a guess, gcc's preprocessor probably emits these rather than #line
directives because #line
directives are intended as input to the preprocessor.
在技术上是一个非指令(只是为了增加乐趣,是一种指令)。就C标准而言,它本质上是一个评论。猜测一下,gcc的预处理器可能会发出这些而不是#line指令,因为#line指令用作预处理器的输入。
gcc's preprocessor refers to these as "linemarkers"; they're discussed in the cpp manual. They're treated like #line
directives, except that they can take an additional flag argument.
gcc的预处理器将这些称为“线性标记”;他们在cpp手册中讨论过。它们被视为#line指令,除了它们可以采用额外的标志参数。
#3
1
The preprocessors tend to introduce these directives and use them to indicate the line and filename. The C++ doesn't define the meaning but it reserves the use of
预处理器倾向于引入这些指令并使用它们来指示行和文件名。 C ++没有定义含义,但它保留了使用
# <non-directive>
where is something which isn't one of the normal directives. It seems compiler writes have agreed to use the line number and filename in these as the result of preprocessing the file. This use is similar to basically all compilers supporting the -E
option to indicate that the file(s) should just be processed.
哪里不是正常指令之一。似乎编译器写入同意使用这些中的行号和文件名作为预处理文件的结果。这种用法类似于基本上所有支持-E选项的编译器,以指示应该只处理文件。
#1
18
This is output from the GCC preprocessor. Those lines are known as linemarkers. They have the syntax:
这是GCC预处理器的输出。这些行被称为行标记。他们有语法:
# linenum filename flags
They are interpreted as saying that the following line has come from the line linenum
from filename
. They basically just help you and the compiler see where lines were included from. The flags provide some more information:
他们被解释为说以下行来自文件名的line linenum。它们基本上只是帮助您和编译器查看包含行的位置。标志提供了更多信息:
1
- This indicates the start of a new file.1 - 这表示新文件的开始。
2
- This indicates returning to a file (after having included another file).2 - 这表示返回文件(包含另一个文件后)。
3
- This indicates that the following text comes from a system header file, so certain warnings should be suppressed.3 - 这表示以下文本来自系统头文件,因此应禁止某些警告。
4
- This indicates that the following text should be treated as being wrapped in an implicitextern "C"
block.4 - 这表示以下文本应被视为包含在隐式extern“C”块中。
You can see this output from preprocessing your own programs if you give the -E
flag to g++.
如果给g ++提供-E标志,则可以通过预处理自己的程序来查看此输出。
#2
2
You'll typically see lines like that in the output of the preprocessor (i.e., you normally shouldn't be seeing them at all).
您通常会在预处理器的输出中看到类似的行(即,您通常根本不应该看到它们)。
They're similar to the standard #line
directive, which has the form:
它们类似于标准的#line指令,其形式如下:
#line 42
or
#line 42 "foo.c"
which the compiler uses to control the contents of error messages.
编译器用来控制错误消息的内容。
Without the word line
, this:
没有字线,这个:
# 42 "foo.c"
is technically a non-directive (which, just to add to the fun, is a kind of directive). It's essentially a comment as far as the C standard is concerned. At a guess, gcc's preprocessor probably emits these rather than #line
directives because #line
directives are intended as input to the preprocessor.
在技术上是一个非指令(只是为了增加乐趣,是一种指令)。就C标准而言,它本质上是一个评论。猜测一下,gcc的预处理器可能会发出这些而不是#line指令,因为#line指令用作预处理器的输入。
gcc's preprocessor refers to these as "linemarkers"; they're discussed in the cpp manual. They're treated like #line
directives, except that they can take an additional flag argument.
gcc的预处理器将这些称为“线性标记”;他们在cpp手册中讨论过。它们被视为#line指令,除了它们可以采用额外的标志参数。
#3
1
The preprocessors tend to introduce these directives and use them to indicate the line and filename. The C++ doesn't define the meaning but it reserves the use of
预处理器倾向于引入这些指令并使用它们来指示行和文件名。 C ++没有定义含义,但它保留了使用
# <non-directive>
where is something which isn't one of the normal directives. It seems compiler writes have agreed to use the line number and filename in these as the result of preprocessing the file. This use is similar to basically all compilers supporting the -E
option to indicate that the file(s) should just be processed.
哪里不是正常指令之一。似乎编译器写入同意使用这些中的行号和文件名作为预处理文件的结果。这种用法类似于基本上所有支持-E选项的编译器,以指示应该只处理文件。