this post was submitted on 11 Nov 2025
556 points (97.4% liked)

Programmer Humor

27322 readers
2240 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] azertyfun@sh.itjust.works 1 points 3 days ago (1 children)

if its controlling expression is not a constant expression

Pretty big caveat. If I'm reading this right true definitely qualifies as a constant expression and the loop in the meme would therefore not be optimized away.

[–] henfredemars@lemdro.id 2 points 3 days ago

There's also this part of the standard that throws a wrench into this hypothesis:

§5.1.2.3/4: (Program execution, Observable behavior):

Accesses to volatile objects and calls to library I/O functions are observable behavior. The implementation may perform any transformation of a program, provided that the resulting program’s observable behavior is not changed.

So it seems that running forever isn't an observable property that must be preserved when code is transformed.

Still, I think compilers try to not surprise the developer too badly and would recognize a trivial loop most of the time.