Remix.run Logo
saagarjha an hour ago

What should the behavior above be defined to do?

tsukikage 6 minutes ago | parent | next [-]

“Implementation defined behaviour”: compiler author chooses, and documents the choice.

A lot of UB should be implementation defined behaviour instead; this would much better match programmers’ intuitions as they reason about their code - you can even see it in the comments of this post: it’s always things like “this hardware supports / doesn’t support unaligned accesses”, it’s never nasal demons.

Filligree 37 minutes ago | parent | prev | next [-]

Print x twice. Not all “side effects” care about order.

Better yet, define an order for parameter evaluation.

echoangle 40 minutes ago | parent | prev | next [-]

Couldn’t you just define that function arguments are evaluated left to right?

Or just throw an error.

saagarjha 18 minutes ago | parent [-]

I meant reading the uninitialized variable

jeffffff an hour ago | parent | prev | next [-]

Compilation error

saagarjha 44 minutes ago | parent [-]

It’s hard to detect all UB at compile time

Demiurge 20 minutes ago | parent [-]

It’s harder depending on the language, which is clearly the point.

lll-o-lll an hour ago | parent | prev [-]

HCF

saagarjha 44 minutes ago | parent [-]

I have good news about what UB allows