6 ms·
All this hassle can be avoided by using `cleanup` compiler attribute. Manage classical C resources by auto-cleanup variables and do error-handling the normal w
by howtofly 10mo ago
All this hassle can be avoided by using `cleanup` compiler attribute.
Manage classical C resources by auto-cleanup variables and do error-handling the normal way. If everything is OK, pass the ownership of these resources from auto-cleanup variables to C++ ctor.
Note this approach plays nicely with C++ exception, and will enter C standard in the form of `defer`.
- ranger_danger 10mo agoYes, but now your code is no longer C or C++ standards compliant as it relies on compiler-specific attributes, if that matters to the programmer. Unfortunately, even the Linux kernel is no longer C because they use GCC compiler extensions (and are currently discussing adding MS ones too).
- 1718627440 10mo agoA kernel will make use of asm, and can't abstract over the machine, so it will always be unportable and relying on compiler extensions.
- ranger_danger 10mo agoThe Linux kernel did not always rely on compiler extensions though...
- 1718627440 10mo agoThe kernel once did not need asm? That's a compiler extension, although a popular one.