Name Spaces of Identifiers in C Programming

0
In C programming, identifiers are the names given to entities such as variables, functions, structures, etc. Understanding the concept of name spaces is crucial for avoiding naming conflicts and ensuring the correct reference of identifiers.

Multiple Declarations and Disambiguation

If more than one declaration of a particular identifier is visible at any point in a translation unit, the syntactic context disambiguates uses that refer to different entities. This is achieved through the use of separate name spaces for various categories of identifiers.

Categories of Identifiers

  • Label Names: These are disambiguated by the syntax of the label declaration and use.
  • Tags of Structures, Unions, and Enumerations: These are disambiguated by following any of the keywords `struct`, `union`, or `enum`.
  • Members of Structures or Unions: Each structure or union has a separate name space for its members. These are disambiguated by the type of the expression used to access the member via the `.` or `->` operator.
  • Ordinary Identifiers: All other identifiers, declared in ordinary declarators or as enumeration constants, fall into this category.

Linkage Between Identifiers

There is no linkage between different identifiers. This means that the same identifier can be used independently in different scopes without conflict.

Function Declarations

A function declaration can contain the storage-class specifier `static` only if it is at file scope. This restricts the visibility of the function to the file it is declared in.

Hiding of Declarations

A later declaration might hide a prior declaration. This means that if an identifier is redeclared in an inner scope, the inner declaration will hide the outer one.

Name Space for Tags

There is only one name space for tags even though three are possible (`struct`, `union`, `enum`). This means that a structure, union, and enumeration cannot have the same tag within the same scope.
Tags

Post a Comment

0Comments
Post a Comment (0)