The K&R 2nd ed answer book has the following solution for a variable argument swap macro
#define swap(t, x, y) { t _z; \
_z = y; \
y = x; \
x = _z; }
Visual Studio Express is telling me that y and x must be constant values and that there is an "expected declaration" to the left of the right brace.
Is this formatting out of date?
Edit:
The way that code is formatted won't let me compile for the errors listed above, but the following code seems to be fine:
#define swap(t, x, y) { t _z; _z = y; y = x; x = _z; }
The problem is you have whitespace after the \
line continuation characters. As such, the \
is no longer treated as a line continuation, but just a non-whitespace character. This means the following lines are not part of the macro definition, and the compiler tries to compile them as normal lines. Getting rid of the whitespace after each \
will fix the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With