3 ms·
> Why C doesn't officially have nested functions is, well, that's C! Maybe some day it will. It should anyway But GCC and Clang already support it, and while
by nextaccountic 4y ago
> Why C doesn't officially have nested functions is, well, that's C!
Maybe some day it will. It should anyway
But GCC and Clang already support it, and while I can't find if MSVC does, it probably does
edit: also, now I see that the goto in if (errno) goto err is really just an (inlined) tail call!
- ndesaulniers 4y agoClang doesn't support the GNU C extension for nested functions.
- int_19h 4y agoMSVC does not support it. In general, any random C compiler is likely to not support that feature, because the way it interacts with function pointers makes it unnecessarily complicated.
- WalterBright 4y ago> unnecessarily complicated Pascal could do it in the 1970s, and even Tiny Pascal could do it, see the listing for the compiler in BYTE. https://archive.org/details/byte-magazine-1978-09 https://archive.org/details/byte-magazine-1978-09 As for function pointers, a simple solution is to not allow them unless the function is declared `static`. `static` functions don't have a hidden static link.
- int_19h 4y agoThe problem isn't doing it as such; ALGOL 60 could do nested functions just fine. The problem is doing it in an ABI-compatible way when you already have an ABI. The gcc implementation of nested functions does that - they are compatible with regular function pointers - but at the cost of requiring executable stack on at least some platforms. And for C compilers that aren't gcc, the question becomes: why partially implement a non-standard gcc feature?