Lets say we have defined macro SWAP:
#define SWAP(a,b) {\
int tmp = a; \
a = b; \
b = tmp;}\
and using SWAP we need to sort 3 numbers (just write another macro which uses macro called SWAP):
#define SORT(a,b,c) \
(a > b) ? SWAP(a,b) : ((a > c) ? SWAP(a,c) : ((b>c) : SWAP(b,c)))
I wrote it like this but my code shows only some errors:
#include <stdio.h>
#define SWAP(a,b) {\
int tmp = a; \
a = b; \
b = tmp;}\
#define SORT(a,b,c) \
(a > b) ? SWAP(a,b) : ((a > c) ? SWAP(a,c) : ((b>c) : SWAP(b,c)))
int main()
{
int a = 1024, b = 7, c = 11;
printf("a = %d b = %d\n", a, b);
SWAP(a,b)
printf("a = %d b = %d\n", a, b);
printf("a = %d b = %d c = %d\n", a, b);
SORT(a,b,c)
printf("a = %d b = %d c = %d\n", a, b);
return 0;
}
errors I get:
error: expected expression before ‘{’ token|