Hacker News new | ask | show | jobs
by ryao 877 days ago
The first 4 are implementation defined rather than undefined.

That said, warnings do not necessarily mean that the code is invoking undefined behavior. For example, with if (a = b) GCC will generate a warning, unless you do if ((a = b)). The reason for the warning is that often people mean to do equality and instead write assignment by mistake, so the compilers warn unless a second set of braces is used to signal that you really meant to do that.

2 comments

In the cases involving overflow, it's implementation-defined whether there's undefined behavior.
> The first 4 are implementation defined rather than undefined.

Third and fourth are only defined in some implementations.

That is fair for 4, although would explain why it is the case for 3?
If char is signed and ' ' * 13 is bigger than CHAR_MAX, you get UB by signed overflow.