News for hackers. Stuff that matters.
Re:Stupid Smart Pointers in C by masklinn on Monday March 17, 2025 @09:27AM (#43388375)
In Go, defers are function scoped not block scoped.
Re:Stupid Smart Pointers in C by DanielHB on Monday March 17, 2025 @11:12AM (#43389422)
Right, that makes more sense.
Re:Stupid Smart Pointers in C by TheDong on Monday March 17, 2025 @10:06AM (#43388750)
I mean, you just write all your scopes as `(func() { })()` in go, and it works out fine.

Adding `func() {}()` scopes won't break existing code usually, though if you use 'break' or 'continue' you might have to make some changes to make it compile, like so:

https://go.dev/play/p/_Gq4QYtyMmp

see, no other issues, works exactly like you'd expect