understanding C namespaces

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

    But the crucial point on your examples isn't about namespace, but the scope of the names.

    In name.c, both long2 are "ordinary identifiers" (share the same name space), and both of them are defined in the same scope, so there is a conflict. (C99 §6.7/3)

    If name2.c, the local variable four is in a scope deeper than the function four, so the variable hides the function four (C99 §6.2.1/4).

提交回复
热议问题