新手求解,GCC编译不通过,自己看不出问题
RT,
#include <stdio.h>
#include <stdlib.h>
#define MALLOC (p, s) \
if(!((p)=malloc(s))) \
{ \
fprintf(stderr,"Insufficient Memory");\
exit(EXIT FAILURE); \
}
int main()
{
int i, *pi;
float f, *pf;
MALLOC (pi, sizeof(int));
MALLOC (pf, sizeof(float));
*pi=1024;
*pf=3.14;
printf("an integer = %d, a float = %f\n", *pi, *pf);
free(pi);
free(pf);
return 0;
}
GCC 报错如下:
1-1.c: 在函数‘main’中:
1-1.c:3:18: 错误:‘p’未声明(在此函数内第一次使用)
#define MALLOC (p, s) \
^
1-1.c:13:2: 附注:in expansion of macro ‘MALLOC’
MALLOC (pi, sizeof(int));
^
1-1.c:3:18: 附注:每个未声明的标识符在其出现的函数内只报告一次
#define MALLOC (p, s) \
^
1-1.c:13:2: 附注:in expansion of macro ‘MALLOC’
MALLOC (pi, sizeof(int));
^
1-1.c:3:21: 错误:‘s’未声明(在此函数内第一次使用)
#define MALLOC (p, s) \
^
1-1.c:13:2: 附注:in expansion of macro ‘MALLOC’
MALLOC (pi, sizeof(int));
^
1-1.c:4:3: 错误:expected expression before ‘if’
(if(!((p)=malloc(s))) \
^
1-1.c:13:2: 附注:in expansion of macro ‘MALLOC’
MALLOC (pi, sizeof(int));
^
1-1.c:4:3: 错误:expected expression before ‘if’
(if(!((p)=malloc(s))) \
^
1-1.c:14:2: 附注:in expansion of macro ‘MALLOC’
MALLOC (pf, sizeof(float));