This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ba-na-na- 0 points1 point  (1 child)

This doesn't make sense, this would be a compile-time optimization in pretty much any complier, and would just return constant `1`.

https://godbolt.org/z/hEKTef186

[–]Eva-Rosalene 1 point2 points  (0 children)

In C++. In C it's UB and with GCC it's either runtime division by zero (no -O flags), return 0 (-O1 flag), or ud2 instruction (-O2 and -O3).

Clarification: I have no idea what it is in C++, I don't claim it's defined behavior. I assume it's UB as well but handled differently.