Is there a use for function declarations inside functions?

前端 未结 4 1277
时光取名叫无心
时光取名叫无心 2020-12-01 21:06

We can declare functions inside functions (I wanted a local variable, but it parses as a function declaration):

struct bvalue;
struct bdict {
    bd         


        
4条回答
  •  不知归路
    2020-12-01 21:22

    It's useful if you need to use an external function whose name would conflict with an internal (static) function or variable in the current translation unit (source file). For instance (silly but it gets the point across):

    static int read(int x)
    {
        return bar(x);
    }
    
    static int foo()
    {
        ssize_t read(int, void *, size_t);
        read(0, buf, 1);
    }
    

提交回复
热议问题