understanding C namespaces

前端 未结 4 1323
长情又很酷
长情又很酷 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:16

    C has four different name spaces for identifiers:

    • Label names (the goto type).
    • Tags (names of structures, unions and enumerations).
    • Members of structures and unions (these have a separate namespace per structure/union).
    • All other identifiers (function names, object names, type(def) names, enumeration constants, etc).

    See also C99 6.2.3.

    So your two question can be answered as:

    1. Yes, function names and typedef names share the same name space.
    2. No conflict, because the compiler will use scope rules (for function or object names). The identifier in main is said to shadow the global function name, something your compiler will warn you about if you set the warning levels high enough.

提交回复
热议问题