3 ms·
No. It is not "undefined behavior". The "behavior" here is assignment (reading memory). It always will behave precisely and consistently: it _will_ assign the "
by eternalban 7y ago
No. It is not "undefined behavior". The "behavior" here is assignment (reading memory). It always will behave precisely and consistently: it _will_ assign the "indeterminite" value of the un-initialized memory. Using such an "indeterminite value" in other operations (e.g comparison per the link Steve B. posted above: https://www.ralfj.de/blog/2019/07/14/uninit.html https://www.ralfj.de/blog/2019/07/14/uninit.html) is the UB bit.
- throwaway_pdp09 7y ago> [reading memory} always will behave precisely and consistently What is the point of not making it UB? You can't AFAICS possibly rely on any useful way on it behaving 'precisely and consistently' so just make it UB anyway?
- saagarjha 7y agoI think this lets you copy it around, e.g. when you have a struct that you have partially initialized.
- throwaway_pdp09 7y agoThat makes sense, finally. Thanks.