Nested function in C

前端 未结 9 1705
眼角桃花
眼角桃花 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:44

    I mention this as many people coding in C are now using C++ compilers (such as Visual C++ and Keil uVision) to do it, so you may be able to make use of this...

    Although not yet permitted in C, if you're using C++, you can achieve the same effect with the lambda functions introduced in C++11:

    void f()
    {
        auto g = [] () { /* Some functionality */ }
    
        g();
    }
    

提交回复
热议问题