-2
#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';

因此它会引发错误,请提供答案。

4

2 回答 2

1

简单的答案:不要使用宏将 int 更改为 long。

如果你真的必须这样做,你可以这样做:

#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];
#define int int
    if (isspace(c)) c='\n';
#define int long
    putchar (c);
    i++;
  }
  return 0;
}
于 2012-08-13T04:25:36.440 回答
0
#define int long

这是一个非常糟糕的主意。不要这样做。

linux环境报错

不,它没有。使用 gcc 编译和执行就好了。

当我通过宏将 int 更改为 long

这是一个非常糟糕的主意。不要这样做。

您的问题的答案是:如果您尝试使用宏重新发明 C 语言,将会发生不好的事情,而您只能靠自己来解决它们。

于 2012-08-13T06:15:01.573 回答