curious about why an almost equivalent C code can avoid LoadProhibited error
Posted: Tue Nov 08, 2022 5:04 pm
```c
STATIC mp_int_t getuwidth(mp_int_t cord) {
mp_int_t uw = 0;
switch (chrtype(cord)) {
case 0: uw = 1;
break;
case 1: uw = 1;
break;
case 2: uw = 2;
break;
case 3: uw = 2;
break;
case 4: uw = 2;
break;
}
return uw;
}
```
After being executed for 20+ time, it will cause LoadProhibited error.
```c
STATIC mp_int_t getuwidth(mp_int_t cord) {
if (chrtype((uint32_t)cord) <= 1) {
return 1;
} else {
return 2;
}
}
```
But this have no such problem, why?
STATIC mp_int_t getuwidth(mp_int_t cord) {
mp_int_t uw = 0;
switch (chrtype(cord)) {
case 0: uw = 1;
break;
case 1: uw = 1;
break;
case 2: uw = 2;
break;
case 3: uw = 2;
break;
case 4: uw = 2;
break;
}
return uw;
}
```
After being executed for 20+ time, it will cause LoadProhibited error.
```c
STATIC mp_int_t getuwidth(mp_int_t cord) {
if (chrtype((uint32_t)cord) <= 1) {
return 1;
} else {
return 2;
}
}
```
But this have no such problem, why?