|
|
|
|
|
by cjensen
2946 days ago
|
|
It's undefined for a reason. size_t size = unreasonable large number;
char buf = malloc (size);
char *mid = buf + size / 2;
int index = 0;
for (size_t x = 0; x < big number; x++) mid[index++] = x;
A common optimization by a compiler is to introduce a temporary char *temp = mid + index;
prior to the loop and then replace the body of the loop with *(temp++) = x;
If the compiler has to worry about integer overflow, this optimization is not valid.(I'm not a compiler engineer. Losing the optimization may be worth-while. Or maybe compilers have better ways of handling this nowadays. I'm just chiming in on why int overflow is intentionally undefined in the Fine Standard) |
|