先輩にgccは関数の入れ子(ネスト)定義ができることを聞いた件の覚書。
manみたら、Darwin(Max OS X)だと、これは元々は無効になってるらしく(-fnonested-functions)、-fnested-functionsで有効にしてやんないといけないらしい。
以下ソース。
/* nest.c */ #include <stdio.h> int hello(void) { int sayhello(void) { printf("hello\n"); return 0; } int saygoodbye(void) { printf("good-bye\n"); return 0; } sayhello(); saygoodbye(); sayhello(); return 0; } int main(void) { hello(); return 0; }
>gcc nest.c nest.c: In function ‘hello’: nest.c:6: error: nested functions are disabled, use -fnested-functions to re-enable nest.c:11: error: nested functions are disabled, use -fnested-functions to re-enable > >gcc -fnested-functions nest.c >./a.out hello good-bye hello
linuxでは試してない。
へぇ〜 でも意味あんのかなwww
自分基本的には--ansiオプション付けてコンパイルするくらいだから、使う機会はまずないだろうなwww
ってか関数のグローバルじゃない定義ができるとか、もはやCじゃないだろwww