OPTION EXPLICITARRAY: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:OPTION _EXPLICITARRAY}} OPTION _EXPLICITARRAY instructs the compiler to require arrays be declared with DIM, REDIM or equivalent. {{PageSyntax}} : OPTION _EXPLICITARRAY {{PageDescription}} * Normally statements like {{InlineCode}}x(2) = 3{{InlineCodeEnd}} will implicitly create an array x(). OPTION _EXPLICITARRAY requires a preceding declaration for the array, helping to catch mistyped array and function names. * Unlike OPTION _E...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:OPTION _EXPLICITARRAY}}
{{DISPLAYTITLE:OPTION _EXPLICITARRAY}}
[[OPTION _EXPLICITARRAY]] instructs the compiler to require arrays be declared with [[DIM]], [[REDIM]] or equivalent.
[[OPTION _EXPLICITARRAY]] instructs the compiler to require arrays to be properly dimensioned with [[DIM]] or [[REDIM]] before first use. However, it doesn't require regular variables to be declared.
 


{{PageSyntax}}
{{PageSyntax}}
Line 7: Line 8:


{{PageDescription}}
{{PageDescription}}
* Normally statements like {{InlineCode}}x(2) = 3{{InlineCodeEnd}} will implicitly create an array x(). [[OPTION _EXPLICITARRAY]] requires a preceding declaration for the array, helping to catch mistyped array and function names.
* Normally statements like {{InlineCode}}x(2) = 3{{InlineCodeEnd}} will implicitly create an array x(). [[OPTION _EXPLICITARRAY]] requires proper dimensioning for the array, helping to catch mistyped array and function names.
* Unlike [[OPTION _EXPLICIT]], simple variables can still be used without a declaration. Example: {{InlineCode}}i = 1{{InlineCodeEnd}}
* Unlike [[OPTION _EXPLICIT]], simple variables can still be used without a declaration. Example: {{InlineCode}}i = 1{{InlineCodeEnd}}


{{PageErrors}}
=== Errors ===
* If used, [[OPTION _EXPLICITARRAY]] 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]]).
* If used, [[OPTION _EXPLICITARRAY]] 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]]).
* Do not use [[OPTION _EXPLICITARRAY]] in [[$INCLUDE]]d modules.
* Do not use [[OPTION _EXPLICITARRAY]] in [[$INCLUDE]]d modules.



Latest revision as of 15:19, 25 September 2024

OPTION _EXPLICITARRAY instructs the compiler to require arrays to be properly dimensioned with DIM or REDIM before first use. However, it doesn't require regular variables to be declared.


Syntax

OPTION _EXPLICITARRAY


Description

  • Normally statements like x(2) = 3 will implicitly create an array x(). OPTION _EXPLICITARRAY requires proper dimensioning for the array, helping to catch mistyped array and function names.
  • Unlike OPTION _EXPLICIT, simple variables can still be used without a declaration. Example: i = 1

Errors


Examples

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

OPTION _EXPLICITARRAY
x = 1 'This is fine, it's not an array so not affected

DIM z(5)
z(2) = 3 'All good here, we've explicitly DIMmed our array

y(2) = 3 'This now generates an error

QB64 IDE Status will show: Array 'y' (SINGLE) not defined on line 7


See also



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