code example of macro which returns a value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

#define check(condition)                   \
    ({                                     \
        int __ret = 0;                     \
        if (!(condition))                  \
        {                                  \
            printf("Condition failed!\n"); \
            __ret = -1;                    \
        }                                  \
        __ret;                             \
    })

int main()
{
    int x = 10;
    int result = check(x > 15);

    printf("result: %d", result);
    return 0;
}