Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

defer has nothing to do with C++.


C++ has try finally, which is the same thing. Instead of bloating C, anyone needing defer can use a subset of C++ that fits their needs.


Maybe you're mixing up with SEH (Structured Exception Handling) which is a Microsoft extension to C that came even before C++


So we moved from “defer” to “using a different language, with different semantics, and use the non-standard finally”.


C++ has no finally blocks.


> C++ has no finally blocks.

Not in the standard, but there are compiler implementations (like Microsoft’s) that have added it.


I just did a gh code search (__finally lang:c++), a hundred-ish instances shows up in ~12 repos mainly related to MS / .Net:

‎ sleuthkit/scalpel‎

‎‎ microsoft/service-fabric‎

‎ ‎dotnet/runtime‎

‎ ‎microsoft/Detours‎

‎ ‎dotnet/wpf‎

‎ ‎Chuyu-Team/VC-LTL‎

‎ ‎apache/logging-log4net‎

‎ ‎microsoft/Windows-classic-samples‎

‎ ‎microsoft/winfile‎

‎ ‎dotnet/llilc‎

‎‎ microsoft/DirectXShaderCompiler‎

‎ ‎dotnet/diagnostics‎

‎‎ SoftEtherVPN/SoftEtherVPN‎

‎ ‎microsoft/PTVS‎

‎ ‎aybe/Windows-API-Code-Pack-1.1‎

I don't think that it's in any way meaningful, it's literally unused given that it's been there for likely 20+ years.


You mix that up with RAII.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: