I wrote this code to test static_assert
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <inttypes.h>
#define static_assert _Static_assert
typedef enum {ONE=1, TWO, THREE} num_t;
uint8_t Is_Num_Valid(num_t number){
uint8_t i = 0;
for(i=1;i<4;i++){
if(number == i){
return 1;
}
}
return 0;
}
int main()
{
num_t number;
number = ONE;
printf("%d\n", Is_Num_Valid(number));
if(Is_Num_Valid(number)){
static_assert(0, "Number entered is out of boundaries");
}
printf("Number is> %d\n", number);
return 0;
}
Which always results in a compilation error error: static assertion failed: "Number entered is out of boundaries"
why this is not working, it should not execute the body of if() if the condition is 0!!!