小编hsp*_*pim的帖子

对于#define中的循环

#include <stdio.h>
#define UNITS {'*', '#', '%', '!', '+', '$', '=', '-'}

#define PrintDigit(c, d) (for (i=0; i < c ; i++)putchar(unit[d]);)

char unit[] = UNITS;

//void PrintDigit(c, element) {
//  int i;
//  for (i=0; i < c ; i++)
//      putchar(unit[element]);
//}


int main( ) {
    int i, element=4;
    PrintDigit(10, element);
    putchar('\n');
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我在这里的功能PrintDigit()按预期工作.当试图将函数转换为#define时,gcc不断在for循环中抛出语法错误.知道问题是什么吗?

c loops for-loop c-preprocessor

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

标签 统计

c ×1

c-preprocessor ×1

for-loop ×1

loops ×1