#include可以使用预处理令牌吗? [英] Can #include use a preprocessing token?
问题描述
#include可以安全地使用预处理令牌,如
#define HEADERFILE" stdio.h"
#include HEADERFILE
int main(void){return printf(" Hello,world \ n")* 0;}
TIA,
Fran ?ois Grieu
Can #include safely use a preprocessing token, as in
#define HEADERFILE "stdio.h"
#include HEADERFILE
int main(void) {return printf("Hello, world\n")*0;}
TIA,
Fran?ois Grieu
推荐答案
Francois Grieu写道:
Francois Grieu wrote:
#include可以安全地使用预处理令牌,如在
#define HEADERFILE" stdio.h"
#include HEADERFILE
int main(void){return printf(" Hello,world \ n")* 0 ;}
cat main.c
#define HEADERFILE" stdio.h"
#include HEADERFILE
int main(int argc,char * argv []){
返回printf(" Hello,world!\ n")* 0;
}
gcc -Wall -std = c99 -pedantic -o main main.c
./main
Can #include safely use a preprocessing token, as in
#define HEADERFILE "stdio.h"
#include HEADERFILE
int main(void) {return printf("Hello, world\n")*0;} cat main.c #define HEADERFILE "stdio.h"
#include HEADERFILE
int main(int argc, char* argv[]) {
return printf("Hello, world!\n")*0;
}
gcc -Wall -std=c99 -pedantic -o main main.c
./main
你好,世界!
为什么,是的!看来你可以。
Hello, world!
Why, yes! It appears that you can.
" E. Robert Tisdale <,E ************** @ jpl.nasa.gov>。写道:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
Francois Grieu写道:
Francois Grieu wrote:
#include可以安全地使用预处理令牌,如
#定义HEADERFILE" stdio.h"
#include HEADERFILE
int main(void){return printf(" Hello,world \ n")* 0;}
Can #include safely use a preprocessing token, as in
#define HEADERFILE "stdio.h"
#include HEADERFILE
int main(void) {return printf("Hello, world\n")*0;}
> cat main.c
> cat main.c
#define HEADERFILE" stdio.h"
#include HEADERFILE
int main(int argc,char * argv [ ])
返回printf(Hello,world!\ n)* 0;
}
#define HEADERFILE "stdio.h"
#include HEADERFILE
int main(int argc, char* argv[]) {
return printf("Hello, world!\n")*0;
}
> gcc -Wall -std = c99 -pedantic -o main main.c
> ./main
> gcc -Wall -std=c99 -pedantic -o main main.c
> ./main
你好,世界!
为什么,是的!看来你可以。
Hello, world!
Why, yes! It appears that you can.
好吧,不。看来你可以_using GCC_。鉴于Gnu人的相当严格的b
拥抱和延伸习惯,这绝对告诉你
无关于ISO C.
当然,你_can_实际上在ISO C中执行上述操作,你甚至不需要一个C99编译器,就像你的命令行似乎建议的那样。但是
结论可以从ISO C标准中的#include
指令的定义中得出,_not_来自使用Ganuck的测试。
>
Richard
Well, no. It appears that you can _using GCC_. Given the rather severe
embrace-and-extend habits of the Gnu people, this tells you absolutely
nothing about ISO C.
Of course, you _can_ actually do the above in ISO C, and you don''t even
need a C99 compiler for that, as your command line seems to suggest. But
that conclusion can be drawn from the definition of the #include
directive in the ISO C Standard, _not_ from a test using Ganuck.
Richard
Francois Grieu< fg **** @ francenet.fr>写道:
Francois Grieu <fg****@francenet.fr> wrote:
#include可以安全地使用预处理令牌,如
#define HEADERFILE" stdio.h"
#include HEADERFILE
int main(void){return printf(" Hello,world \ n")* 0;}
Can #include safely use a preprocessing token, as in
#define HEADERFILE "stdio.h"
#include HEADERFILE
int main(void) {return printf("Hello, world\n")*0;}
是。
ISO / IEC 9899:1999
6.10.2源文件包含
[...]
4表格的预处理指令
#include pp-tokens new-line
(与前两种表格中的一种不匹配)是允许的。
预处理令牌在指令中包含后,
处理正常文本。 (每个标识符当前定义为宏名称的
被替换为
预处理标记的替换列表。)所有
替换后生成的指令应该匹配前两个表格中的一个。
[...]
问候。
-
Irrwahn Grausewitz(ir*******@freenet.de)
欢迎来到clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list: http://www.faqs.org/faqs/C-faq / faq /
clc OT指南: http://benpfaff.org/writings/clc/off-topic.html
Yes.
ISO/IEC 9899:1999
6.10.2 Source file inclusion
[...]
4 A preprocessing directive of the form
# include pp-tokens new-line
(that does not match one of the two previous forms) is permitted.
The preprocessing tokens after include in the directive are
processed just as in normal text. (Each identifier currently
defined as a macro name is replaced by its replacement list of
preprocessing tokens.) The directive resulting after all
replacements shall match one of the two previous forms.
[...]
Regards.
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
这篇关于#include可以使用预处理令牌吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!