#Option Explicit

Syntax:

    #option explicit

This option ensures that all variables are dimensioned in the user program. The scope is the user code only, and no other code space, like .h or include files.

#option explicit requires all variables, including bytes, in the user program to be defined.

Variables can be defined and not used within your user program. Unused variables will not allocate memory.

Example:

    'Set chip model
    #chip 16f877a

    'Example command
    #option explicit

    dim myuserflag as byte

    myuserflag = true          ' <<< a Dimensioned variable required by #option explicit

Key line: myuserflag = true — this assignment is only legal because myuserflag was explicitly Dimensioned above; with #option explicit in effect, assigning to an undeclared name anywhere in the user program raises a compile-time error instead of silently creating an implicit variable.

See Also:

  • Variable Lifecycle — how declared variables are allocated and used
  • Dim — the command used to explicitly declare variables