Nested function in C

前端 未结 9 1703
眼角桃花
眼角桃花 2020-11-22 12:24

Can we have a nested function in C? What is the use of nested functions? If they exist in C does their implementation differ from compiler to compiler?

9条回答
  •  感动是毒
    2020-11-22 12:42

    Or you can be smart about it and use the preprocessor in your advantage (source.c):

    #ifndef FIRSTPASS
    #include 
    
    //here comes your "nested" definitions
    #define FIRSTPASS
    #include "source.c"
    #undef FIRSTPASS
    
    main(){
    #else
        int global = 2;
        int func() {printf("%d\n", global);}
    #endif
    #ifndef FIRSTPASS
        func();}
    #endif
    

提交回复
热议问题