Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Automatic cleanup in C using with-statements (github.com/taeber)
28 points by taeber on May 31, 2020 | hide | past | favorite | 7 comments




Yes you can. I did mention GCC's cleanup attribute along with MSVC's try-finally construct. Another user was kind enough to even provide an example in their GitHub issue: https://github.com/taeber/cwith/issues/1.


Hey, it's pretty nice.

Reminds of the old adage - You never code in plain C, you need to first #define some macros and then you can proceed with metaprogramming


Thank you! I'd much prefer to not have to use macros, but I tried to make the with/withif mimic what I wish was a real C statement.


Unless you are doing embedded programming.


Especially when you are doing embedded programming.

You think those GPIO registers are going to encode themselves?


Macros are the lifeblood of embedded C. I have a use case where I need to read, shift, and OR a value, then write back. If I need to do that for more than 1 thing, sure as shit I'll write a macro.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: