我正在尝试将函数写入宏,但它给了我一个'不可分配的错误'。我的宏是这样的:
#define swapmacro(t, x, y) {t temp = x; x = y; y = temp;}
这是我称之为
的代码int x = 4;
int y = 5;
swapmacro(int, 4, 5);
然后它给了我这个错误信息:
stack.c:23:3: error: expression is not assignable
swapmacro(int, 4, 5);
^ ~
stack.c:7:43: note: expanded from macro 'swapmacro'
#define swapmacro(t, x, y) {t temp = x; x = y; y = temp;}
^
stack.c:23:3: error: expression is not assignable
swapmacro(int, 4, 5);
^ ~
stack.c:7:50: note: expanded from macro 'swapmacro'
#define swapmacro(t, x, y) {t temp = x; x = y; y = temp;}
^
答案 0 :(得分:3)
swapmacro(int, 4, 5);
扩展到:
{int temp = 4; 4 = 5; 5 = temp;};
4 = 5
和5 = temp
都不是有效的表达式。整数文字不能是左值。也许你打算这样做:
swapmacro(int, x, y);
答案 1 :(得分:3)