logoalt Hacker News

anilakaryesterday at 10:33 AM2 repliesview on HN

It would have resulted in an uninitialized variable access warning, though.


Replies

ueckeryesterday at 10:41 AM

I don't think so. The value is set in the assignment in the if statement even for the success path. With and without defer you nowadays get only a warning due to the misleading indentation: https://godbolt.org/z/3G4jzrTTr (updated)

mort96yesterday at 10:42 AM

No it wouldn't. 'err' is declared and initialized at the start of the function. Even if it wasn't initialized at the start, it would've been initialized by some earlier fallible function call which is also written as 'if ((err = something()) != 0)'