|
|
|
|
|
by gergo_barany
3211 days ago
|
|
Indeed. Anyway, this guarded version shows the same behavior and, if I got everything right, cannot invoke undefined behavior for any values of p2: #include <limits.h>
int N;
int fn5(int p1, int p2) {
int a = p2;
if (N && INT_MIN / 10.0 <= a && a <= INT_MAX / 10.0)
a *= 10.0;
return a;
}
GCC still does the multiplication as double, Clang still does it as int.(And both evaluate the guards as int, so there.) |
|
A) fraught with edge-case peril
and
B) easily accounted for by the developer (e.g. write "a *= 10;")...