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

Looking at the implementation of libc4life, I think it's full of gcc-isms. C4DEFER() is this:

    #define _C4DEFER(code, _def)				\
      void _def() code;					\
      bool _def_trigger __attribute__((cleanup(_def)))	\
  
    #define C4DEFER(code)				\
      _C4DEFER(code, C4GSYM(def))			\
So, nested functions and gcc attributes.

Nested functions awesome, but they're a gcc extension, and only supported on some architectures anyway, and AFAIK only work if you have an executable stack, which is frowned on these days (because they have to create a callable thunk to stash the nested function's context pointer).

http://stackoverflow.com/questions/8179521/implementation-of...

My understanding is that clang doesn't support nested functions, but it does have its own non-standard extension, blocks. But of course that's still not standard C.

I'm currently writing clunky C89 code for an old compiler (and occasionally, K&R C!), and I got really excited by this library for a moment, but... nope. Non-standard. Can't use it.



I had to draw a line somewhere, and C99 with GNU extensions is where it is. Cleanup attributes and anonymous functions are just too useful to leave behind. And since I'm using clang to develop this, I'm pretty sure it supports nested functions just fine.


Hm. Sounds like they added them --- nested functions certainly weren't supported the last time I looked (because, as you say, they're far too useful, and I hated having to give them up).

Have you had any reports about problems on, e.g., OpenBSD, related to needing an executable stack?


Could be, it's moving fast. Once I realized I could use nested functions to provide anonymous functions and deferred actions with decent syntax in a semi-standardized way, I was hooked :)

Nothing, but I seldom hang around in the BSD crowd these days.




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

Search: