In C++, I see
#include <iostream>
typedef enum {
NORMAL = 0,
EXTENDED
} CyclicPrefixType_t;
void func (CyclicPrefixType_t x) {
if(x < NORMAL){
printf ("lower\n");
}else{
printf ("higher\n");
}
}
int main (void) {
//MUST CAST OR WE GET ERROR
CyclicPrefixType_t cpType = CyclicPrefixType_t(NORMAL - 1);
func (cpType);
return 0;
}
Expected: lower
> It is OK
But in C,
#include <stdio.h>
typedef enum {
NORMAL = 0,
EXTENDED
} CyclicPrefixType_t;
void func (CyclicPrefixType_t x) {
if(x < NORMAL){
printf ("lower\n");
}else{
printf ("higher\n");
}
}
int main (void) {
//NO NEED TO CAST
CyclicPrefixType_t cpType = (NORMAL - 1);
func (cpType);
return 0;
}
Actually Result: Higher
>
It is NOT OK
In this case, (-1) is automatically cast to another value. Anyone can tell me which value is here and how it is converted to Because if you print it(%d), It will still (-1)