Maybe someone out there can help me understand my problem. I'm trying to use a switch statement in a function-like macro, but I keep getting the following error:
error: expected expression before ‘switch’
Here's some example code of what I'm doing. It's not fancy but I'm just trying to get the concept down:
Code:
#include <stdio.h>
#include <stdlib.h>
#define MACRO_SUCCESS 1
#define MACRO_FAILURE 0
#define check_error(error) \
( switch (error) \
{ \
case 1: return MACRO_SUCCESS; \
case 2: return MACRO_FAILURE; \
} \
)
int main (int argc, char *argv[])
{
printf("error flag = %d\n\r", check_error(2));
printf("error flag = %d\n\r", check_error(1));
return 0;
}