Hi dear all,
The following code will fail in clang:
void f (int (*p) (void));
void g (int i)
{
int nestedfunc (void) { return i; }
f (nestedfunc);
}
compile with clang -S test.c got following message
test.c:4:24: error: expected ';' at end of declaration
int nestedfunc (void) { return i; }
^
;
1 error generated.
but gcc -S test.c will be OK.
Many thanks!
Clang does not support nested functions - that's a gcc language extension.
See <http://clang.llvm.org/docs/UsersManual.html#c_unsupp_gcc>, which says:
clang does not support nested functions; this is a complex feature which is infrequently used, so it is unlikely to be implemented anytime soon.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
FWIW, you can use C++11 lambdas or the Blocks extension to do the same thing in a safer way. (Both lambdas and blocks can be used after the enclosing function returns.)
Jordan