【发布时间】:2012-08-09 07:42:21
【问题描述】:
#include <stdio.h>
#include <ctype.h>
#define int long
int main ()
{
char c;
int i=0;
char str[]="Example sentence to test isspace\n";
while (str[i])
{
c=str[i];
if (isspace(c)) c='\n';
putchar (c);
i++;
}
return 0;
}
在linux环境下会报错,因为:
isspace 将扩展为
if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) c='\n';
当我通过宏将 int 更改为 long 时,它将变为
if (((*__ctype_b_loc ())[(long) ((c))] & (unsigned short long) _ISspace)) c='\n';
因此会引发错误,请提供答案。
【问题讨论】:
-
定义一个匹配任何 C 保留字的宏会导致未定义的行为。所以不要那样做。
-
如果您告诉我们编译器 (?) 给您的错误,我们或许可以帮助您解决真正的问题。使用平台定义的类型或宏进行调和肯定不是一个有效的解决方案