Live data from Hacker News

C: Simple Defer, Ready to Use

gustedt.wordpress.com

31–40 of 157 posts

Re: C: Simple Defer, Ready to Use

#31
post #26

Unfortunately, this requires an executable stack, and only works on gcc, though an alternate implementation can work on clang. After a few attempts at defer, I ended up using a cleanup macro that just takes a function and a value to pass to it: https://github.com/aws-greengrass/aws-greengrass-lite/blob/8... Since the attribute or a function-like macro in the attribute position broke the c parsing in some tooling, I m…

It does not need an executable stack: https://godbolt.org/z/K1GTa4jh4

The macro from the article uses nested functions which on gcc are implemented with tramolines that need executable stack.

https://thephd.dev/lambdas-nested-functions-block-expression...

Re: C: Simple Defer, Ready to Use

#32
post #26

Earlier quoted context omitted.

It does not need an executable stack: https://godbolt.org/z/K1GTa4jh4

The macro from the article uses nested functions which on gcc are implemented with tramolines that need executable stack. https://thephd.dev/lambdas-nested-functions-block-expression...

The trampolines are not generated in this case.

Re: C: Simple Defer, Ready to Use

#37
post #32

Earlier quoted context omitted.

The macro from the article uses nested functions which on gcc are implemented with tramolines that need executable stack. https://thephd.dev/lambdas-nested-functions-block-expression...

The trampolines are not generated in this case.

To be fair you're not communicating very well — there are no trampolines being used here because the call site is directly in the same function, so no trampoline is needed with already being in the correct stack frame.

(And also on -O1 and higher the entire call is optimized out and the nested function inlined instead.)

Re: C: Simple Defer, Ready to Use

#40

Unfortunately, this requires an executable stack, and only works on gcc, though an alternate implementation can work on clang. After a few attempts at defer, I ended up using a cleanup macro that just takes a function and a value to pass to it: https://github.com/aws-greengrass/aws-greengrass-lite/blob/8... Since the attribute or a function-like macro in the attribute position broke the c parsing in some tooling, I m…

[deleted]
Post reply on HN