预处理出错 [英] Error in Preprocessing
问题描述
您好,
有人可以解释为什么我在MSVC6.0中编译时出现错误
编译器
#include< stdio.h>
#define PP 1,2,3,4
#define PP_Func( x,y,z,w)(((x)* 1)+((y)* 2)+((z)* 3)+((w)* 4))
#define PP_Val PP_Func(PP)
int main()
{
printf(" \ n%d",PP_Val);
返回0;
}
>
提前致谢,
问候,
Naren。
Hello,
Could anyone explain why I get an error when I compile this in MSVC6.0
compiler
#include <stdio.h>
#define PP 1,2,3,4
#define PP_Func(x,y,z,w) ( ((x)*1) + ((y) * 2) +((z) * 3) + ((w) * 4) )
#define PP_Val PP_Func(PP)
int main()
{
printf ("\n%d", PP_Val );
return 0;
}
Thanks in advance,
Regards,
Naren.
推荐答案
Naren写道:
您好,
任何人都可以解释为什么我在编译时遇到错误MSVC6.0
编译器
#include< stdio.h>
#define PP 1,2,3,4
这和
相同
#define PP(1,2,3,4)
#define PP_Func (x,y,z,w)(((x)* 1) +((y)* 2)+((z)* 3)+((w)* 4))
#define PP_Val PP_Func(PP)
#define PP_Val PP_Func(PP,PP,PP,PP)
int main()
{/>
printf(" \ n%d",PP_Val);
返回0;
}
Hello,
Could anyone explain why I get an error when I compile this in MSVC6.0
compiler
#include <stdio.h>
#define PP 1,2,3,4
That''s the same as
#define PP (1,2,3,4)
#define PP_Func(x,y,z,w) ( ((x)*1) + ((y) * 2) +((z) * 3) + ((w) * 4) )
#define PP_Val PP_Func(PP)
#define PP_Val PP_Func(PP, PP, PP, PP)
int main()
{
printf ("\n%d", PP_Val );
return 0;
}
-
pete
--
pete
在< bv ********** @ ns2.fe.internet.bosch.com> "那仁" < NA ************* @ in.bosch.com>写道:
In <bv**********@ns2.fe.internet.bosch.com> "Naren" <na*************@in.bosch.com> writes:
任何人都可以解释为什么我在MSVC6.0编译时会出现错误
#include< stdio.h> ;
#define PP 1,2,3,4
#define PP_Func(x,y,z,w)(((x)* 1)+(( y)* 2)+((z)* 3)+((w)* 4))
#define PP_Val PP_Func(PP)
^^^^^^^^^ ^^^^^^^^^^^^^^^^^
将此行替换为:
#define XPP_Func(arg)PP_Func( arg)
#define PP_Val XPP_Func(PP)
否则,PP_Func将以PP作为参数调用,而不是它的
扩展。
int main()
>
printf(" \ n%d",PP_Val);
返回0;
}
Could anyone explain why I get an error when I compile this in MSVC6.0
compiler
#include <stdio.h>
#define PP 1,2,3,4
#define PP_Func(x,y,z,w) ( ((x)*1) + ((y) * 2) +((z) * 3) + ((w) * 4) )
#define PP_Val PP_Func(PP) ^^^^^^^^^^^^^^^^^^^^^^^^^^
Replace this line by:
#define XPP_Func(arg) PP_Func(arg)
#define PP_Val XPP_Func(PP)
Otherwise, PP_Func will be invoked with PP as argument, instead of its
expansion.
int main()
{
printf ("\n%d", PP_Val );
return 0;
}
当宏的参数是另一个宏时,你需要一个额外的等级
宏扩展,以便在扩展
宏参数的情况下调用目标宏。这也在常见问题中解释。
完成上面建议的更改并删除包含行
(这是程序正确性所必需的,但不是如果程序只是预处理的
,因为它会产生大量的预处理器输出),预处理器会产生以下输出:
fangorn:〜/ tmp 223> cat test.c
#define PP 1,2,3,4
#define PP_Func(x,y,z,w)(((x)* 1) +((y)* 2)+((z)* 3)+((w)* 4))
#define XPP_Func(arg)PP_Func(arg)
#define PP_Val XPP_Func(PP)
int main()
{
printf(" \ n%d" ;,PP_Val);
返回0;
}
fangorn:〜/ tmp 224> gcc -ansi -E test.c
#1" test.c"
#1"< built-in>"
#1"<命令行>"
#1" test.c"
int main()
{
printf(" \ n%d",(((1)* 1)+((2)* 2)+((3)* 3)+(( 4)* 4)));
返回0;
}
Dan
- -
Dan Pop
DESY Zeuthen,RZ集团
电子邮件: Da ***** @ ifh.de
在< 40 *********** @ mindspring中。 COM> pete< pf ***** @ mindspring.com>写道:
In <40***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Naren写道:
您好,
任何人都可以解释为什么我在编译时出错这在MSVC6.0
编译器中
#include< stdio.h>
#define PP 1,2,3,4
Hello,
Could anyone explain why I get an error when I compile this in MSVC6.0
compiler
#include <stdio.h>
#define PP 1,2,3,4
这和
#define PP(1,2,3,4)
That''s the same as
#define PP (1,2,3,4)
废话。
Nonsense.
#define PP_Func(x,y,z,w)(((x)* 1)+((y)* 2)+ ((z)* 3)+((w)* 4))
#define PP_Val PP_Func(PP)
#define PP_Func(x,y,z,w) ( ((x)*1) + ((y) * 2) +((z) * 3) + ((w) * 4) )
#define PP_Val PP_Func(PP)
#define PP_Val PP_Func(PP, PP,PP,PP)
#define PP_Val PP_Func(PP, PP, PP, PP)
更多废话。
More nonsense.
int main()<印刷品(" \ n%d",PP_Val);
返回0;
}
int main()
{
printf ("\n%d", PP_Val );
return 0;
}
根据您的建议,printf调用扩展为:
printf(" \ n %d,(((1,2,3,4)* 1)+((1,2,3,4)* 2)+((1,2,3,4)* 3)+((1 ,2,3,4)* 4)));
语法上正确,但显然不是OP想要的。
Dan < br $>
-
Dan Pop
DESY Zeuthen,RZ集团
电子邮件: Da ***** @ ifh.de
这篇关于预处理出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!