预处理器字符串替换 [英] pre-processor string replacement
问题描述
大家好,
我有关于字符串更换的以下问题
预处理器声明,
#define status" 23"
#define status" 44"
int main()
{
printf("%s \ n",status);
}
此工作正常并打印44
其中
#define status" 23"
#define status1 status
int main()
{
printf("%s \ n",status);
}
打印23,在预处理器语句中发生字符串替换
本身,这不是1,为什么会这样?
任何人都可以帮我吗?
Hi Everyone,
I have the following question regarding string replacement
pre-processor statement,
#define status "23"
#define status "44"
int main()
{
printf("%s\n", status);
}
this works fine and prints 44
where as
#define status "23"
#define status1 status
int main()
{
printf("%s\n", status);
}
prints 23, string replacement occurs on the pre-processor statement
itself, which is not in case 1, why is it so?
Can anyone help me on this?
推荐答案
>
>
#define status" 23"
#define status1 status
int main( )
{
printf("%s \ n",status);
}
#define status "23"
#define status1 status
int main()
{
printf("%s\n", status);
}
对不起,我的意思是
int main()
{
printf("%s \\ \\ n",status1);
}
Sorry i mean
int main()
{
printf("%s\n", status1);
}
sa ***** @ yahoo.co.in 写道:
大家好,
>
我有关于字符串更换的以下问题
预处理器声明,
#define status" 44"
int main()
{
printf("%s \\ \\ n,状态);
}
此工作正常并打印44
#define status" 23"
#define st atus1状态
int main()
{
printf("%s \ n",status); < br $>
}
打印23,字符串替换发生在预处理器语句上
本身,这不是案例1,为什么是这样吗?
有谁可以帮我这个?
Hi Everyone,
I have the following question regarding string replacement
pre-processor statement,
#define status "23"
#define status "44"
int main()
{
printf("%s\n", status);
}
this works fine and prints 44
where as
#define status "23"
#define status1 status
int main()
{
printf("%s\n", status);
}
prints 23, string replacement occurs on the pre-processor statement
itself, which is not in case 1, why is it so?
Can anyone help me on this?
你期望看到什么?
-
Ian Collins。
What did you expect to see?
--
Ian Collins.
#define status" 23"
#define status" 44"
#define status "23"
#define status "44"
你期望看到什么?
-
Ian Collins。
What did you expect to see?
--
Ian Collins.
i期望用
23代替第二个陈述状态的第一个陈述,所以它将是
#define" 23" 43......
不是这样的,所以我虽然在
预处理器声明中没有发生字符串替换,但是第二个例子我指出证明
理解不正确。
i expect first statement to replace status of second statement with
23, so it would be
#define "23" "43"...
which isn''t the case, so i though string replacement never happens in
pre-processor statement, however the second example i pointed proves
that understanding is not correct.
这篇关于预处理器字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!