Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we use nested if else with #define preprocessor

#define len(a) if (a == 8)   1       \
               else if (a == 3) 0    \
               else -1

this code is just an example how do we use nested if else. I don't want to use ternary operator as in that case i can't use else if statement.

like image 441
uditkumar01 Avatar asked Apr 12 '26 08:04

uditkumar01


1 Answers

Don't abuse the preprocessor. Use a real function:

constexpr auto len(int const a) {
    if (a == 8) return 1;
    if (a == 3) return 0;
    return -1;
}
like image 99
Ayxan Haqverdili Avatar answered Apr 14 '26 21:04

Ayxan Haqverdili