understanding C namespaces

前端 未结 4 1324
长情又很酷
长情又很酷 2020-11-29 03:31

Quoting from here,

In C, there are two different namespaces of types: a namespace of struct/union/enum tag names and a namespace of typedef names.

4条回答
  •  盖世英雄少女心
    2020-11-29 04:22

    Your 2nd example does not show "no conflict". There is a conflict! Try this:

    #include 
    int four(void) { return 4; }
    struct dummy { int member; };
    int main(void) {
        struct dummy four;
        four.member = four();
    }
    

    And now this

    #include 
    int four(void) { return 4; }
    struct dummy { int member; };
    int main(void) {
        int (*fx)(void) = four; /* "save" function */
        struct dummy four;     /* hide it         */
        four.member = fx();    /* use "hidden" fx */
    }
    

    In your 2nd example, the variable four hides the function four().

提交回复
热议问题