小编Moh*_*wez的帖子

为什么预处理器的标记粘贴运算符 ## 不适用于变量?

#if !defined(STDIO_H) && !defined(STDLIB_H)
    #include<stdio.h>
    #include<stdlib.h>
#endif
#if !defined(LIMITS_H)
    #include<limits.h>
#endif
#if !defined(MATH_H)
    #define pow(a,b)    {\
                            int i=1,p=1;\
                            while(i<=b)\
                            {\
                                p=p*a;\
                                i++;\
                            }\
                            printf("%d\n",p);\
                        }
    #define join(a,b)   a##b
#endif
int main()
{
    int a,b;
    printf("Enter a b : ");
    scanf("%d %d",&a,&b);
    pow(a,b);
    printf("%d\n",join(a,b));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误是一致的,printf("%d",join(a,b));但如果我用 56 和 34 之类的常量替换 a & b,它就可以完美运行。

c variables c-preprocessor

1
推荐指数
1
解决办法
59
查看次数

标签 统计

c ×1

c-preprocessor ×1

variables ×1