当我尝试编译这个程序时,我在程序错误中遇到了迷路的“#”
I get stray '#' in program error when I try to compile this program
当我尝试使用 -fopenmp
标志进行编译时,出现以下错误:
stray #
in program
下面是我的代码:
#include<omp.h>
int main()
{ #pragma omp parallel
{
int id=0;
printf("hello(%d) ",id);
printf("world(%d)\n",id);
}
}
引用 C11
,章节 §6.10/p2,"Preprocessing directives"(强调我的)
A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the
following constraints: The first token in the sequence is a #
preprocessing token that (at
the start of translation phase 4) is either the first character in the source file (optionally
after white space containing no new-line characters) or that follows white space
containing at least one new-line character. The last token in the sequence is the first newline
character that follows the first token in the sequence.
因此,您不能在任何其他 令牌 之后添加 #
。在你的代码中
int main()
{ #pragma omp parallel
^ ^^^
语法违反约束,因此出现错误。您必须将其放在 自己的 行中。
当我尝试使用 -fopenmp
标志进行编译时,出现以下错误:
stray
#
in program
下面是我的代码:
#include<omp.h>
int main()
{ #pragma omp parallel
{
int id=0;
printf("hello(%d) ",id);
printf("world(%d)\n",id);
}
}
引用 C11
,章节 §6.10/p2,"Preprocessing directives"(强调我的)
A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the following constraints: The first token in the sequence is a
#
preprocessing token that (at the start of translation phase 4) is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character. The last token in the sequence is the first newline character that follows the first token in the sequence.
因此,您不能在任何其他 令牌 之后添加 #
。在你的代码中
int main()
{ #pragma omp parallel
^ ^^^
语法违反约束,因此出现错误。您必须将其放在 自己的 行中。