Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Nested functions are not supported on MacOSX

Name: Anonymous 2006-01-03 17:24

You wanted a programming thread?


(This, by the way, refers to nested functions in C code. A gcc extension)

"gcc's implementation of nested functions involves placing code on the stack and then executing it. Stack execution is a common operation in malicious code, particularly as a side effect of buffer overflows. While the proper fix is of course to not make buffer overflows possible in the first place, disabling stack execution decreases the likelihood that a buffer overflow or other stack-smashing attack will be exploitable."

"In future releases of Mac OS X, we may disable stack execution. (Obviously we'll have to keep binary compatibility in mind when or if we do that.) Nested functions were disabled to help prepare for that change."

"As for whether nested functions will be re-enabled, if someone contributes a patch to GCC to change the nested function implementation to not rely on stack execution, presumably there'd be a chance they'd be re-enabled."


Are Apple evil or awesome for doing this? (discussion!)

How would you go about implementing nested functions without using stack execution? (technical challenge!)

Or we could go back to flaming Java.

Name: Anonymous 2011-07-28 21:03

Nested functions in GCC are stupid and non-standard. Dynamic execution from the stack is retarded.

Apple is dropping GCC completely from Mac OS X in the near future--they aren't investing tons of effort into Clang/LLVM for nothing. So even if a patch is introduced, don't except it to be availabe on OS X. Hell, even FreeBSD is transitioning completely to Clang/LLVM.

Recent versions of Clang are capable of performing numerous tail-call optimizations in almost all circumstances, the only restriction is it doesn't work on functions with variadic argument lists (such printf(char const* f, ...);).

C++0x/C++1x has lambdas/closures, and Clang also supports Apple's blocks extensions which is a somewhat simpler and more restricted implementation of lambdas/closures than the C++11 version.

There's no reason to use GCC style nested functions when the alternatives are superior.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List