mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

SCOPE AND VISIBILITY

Scope

The scope of identifier is the part of the program in which the identifier can be used to access its object. There are different categories of scope: block (or local), function, function prototype, and file. These depend on how and where identifiers are declared.

Block Scope

The scope of an identifier with block (or local) scope starts at the declaration point and ends at the end of the block containing the declaration (such a block is known as the enclosing block). Parameter declarations with a function definition also have block scope, limited to the scope of the function body.

File Scope

File scope identifiers, also known as globals, are declared outside of all blocks; their scope is from the point of declaration to the end of the source file.

Function Scope

The only identifiers having function scope are statement labels. Label names can be used with goto statements anywhere in the function in which the label is declared. Labels are declared implicitly by writing label_name: followed by a statement. Label names must be unique within a function.

Function Prototype Scope

Identifiers declared within the list of parameter declarations in a function prototype (not part of a function definition) have function prototype scope. This scope ends at the end of the function prototype.

Tag Scope

Structure, union, and enumeration tags are somewhat specific in mikroC. Due to separate name space, tags are virtually removed from normal scope rules: they have file scope, but override any block rules. Thus, deeply nested declaration of structure is identical to an equivalent global declaration. As a consequence, once that you have defined a tag, you cannot redefine it in any block within file.

page

 

54

MikroElektronika: Development tools - Books - Compilers