Name Spaces

Name space is a scope within which an identifier must be unique. The mikroC PRO for PIC32 uses four distinct categories of identifiers:

  1. goto label names - must be unique within the function in which they are declared.
  2. Structure, union, and enumeration tags - must be unique within the block in which they are defined. Tags declared outside of any function must be unique.
  3. Structure and union member names - must be unique within the structure or union in which they are defined. There is no restriction on the type or offset of members with the same member name in different structures.
  4. Variables, typedefs, functions, and enumeration members - must be unique within the scope in which they are defined. Externally declared identifiers must be unique among externally declared variables.

Duplicate names are legal for different name spaces regardless of the scope rules.

For example:

int blue = 73;

{ // open a block
   enum colors { black, red, green, blue, violet, white } c;
   /* enumerator blue = 3 now hides outer declaration of int blue */

   struct colors { int i, j; };   // ILLEGAL: colors duplicate tag
   double red = 2;                // ILLEGAL: redefinition of red
}

blue = 37;                       // back in int blue scope
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code