OPTION EXPLICIT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:OPTION _EXPLICIT}} OPTION _EXPLICIT instructs the compiler to require variable declaration with DIM, REDIM or an equivalent statement. {{PageSyntax}} : OPTION _EXPLICIT {{PageDescription}} * With OPTION _EXPLICIT you can avoid typos by having QB64 immediately warn in the '''Status area''' of new variables used without previous declaration. * Enable OPTION _EXPLICIT temporarily even if a program source file doesn't contain the...")
 
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:OPTION _EXPLICIT}}
{{DISPLAYTITLE:OPTION _EXPLICIT}}
[[OPTION _EXPLICIT]] instructs the compiler to require variable declaration with [[DIM]], [[REDIM]] or an equivalent statement.
[[OPTION _EXPLICIT]] instructs the compiler to require variable declaration with [[DIM]], [[REDIM]] or an equivalent statement.


Line 9: Line 9:
{{PageDescription}}
{{PageDescription}}
* With [[OPTION _EXPLICIT]] you can avoid typos by having QB64 immediately warn in the '''Status area''' of new variables used without previous declaration.
* With [[OPTION _EXPLICIT]] you can avoid typos by having QB64 immediately warn in the '''Status area''' of new variables used without previous declaration.
* The use of [[OPTION _EXPLICIT]] does also enforce the requirement to [[DIM]] or [[REDIM]] any arrays before first use, no extra [[OPTION _EXPLICITARRAY]] is needed.
* Enable [[OPTION _EXPLICIT]] temporarily even if a program source file doesn't contain the directive by specifying the '''-e''' switch when compiling via command line (''qb64 -c file.bas -e'').
* Enable [[OPTION _EXPLICIT]] temporarily even if a program source file doesn't contain the directive by specifying the '''-e''' switch when compiling via command line (''qb64 -c file.bas -e'').


 
=== Errors ===
{{PageErrors}}
* If used, [[OPTION _EXPLICIT]] must be the very first statement in your program. No other statements can precede it (except for comment lines started with an [[Apostrophe|apostrophe]] or [[REM]]).
* If used, [[OPTION _EXPLICIT]] must be the very first statement in your program. No other statements can precede it (except for [[$NOPREFIX]] or comment lines started with an [[Apostrophe|apostrophe]] or [[REM]]).
* Do not use [[OPTION _EXPLICIT]] in [[$INCLUDE]]d modules.
* Do not use [[OPTION _EXPLICIT]] in [[$INCLUDE]]d modules.


Line 33: Line 33:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1727 Featured in our "Keyword of the Day" series]
* [[OPTION _EXPLICITARRAY]]
* [[OPTION _EXPLICITARRAY]]
* [[DIM]], [[REDIM]]
* [[DIM]], [[REDIM]]

Latest revision as of 15:19, 25 September 2024

OPTION _EXPLICIT instructs the compiler to require variable declaration with DIM, REDIM or an equivalent statement.


Syntax

OPTION _EXPLICIT


Description

  • With OPTION _EXPLICIT you can avoid typos by having QB64 immediately warn in the Status area of new variables used without previous declaration.
  • The use of OPTION _EXPLICIT does also enforce the requirement to DIM or REDIM any arrays before first use, no extra OPTION _EXPLICITARRAY is needed.
  • Enable OPTION _EXPLICIT temporarily even if a program source file doesn't contain the directive by specifying the -e switch when compiling via command line (qb64 -c file.bas -e).

Errors


Examples

Example: Avoiding simple typos with OPTION _EXPLICIT results shown in the QB64 IDE Status area.

OPTION _EXPLICIT

DIM myVariable AS INTEGER

myVariable = 5

PRINT myVariabe

QB64 IDE Status will show: Variable 'myVariabe' (SINGLE) not defined on line 4


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link