[cfe-dev] failed gcc nested function

Marshall Clow mclow.lists at gmail.com
Tue Aug 21 07:42:40 PDT 2012


On Aug 21, 2012, at 7:14 AM, Shang Yu <yusunn at gmail.com> wrote:

> 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.

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 at 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





More information about the cfe-dev mailing list