Syntax:
For Variables: Dim variable // will define a Byte variable Dim variable [As type] Dim variable [As type] [= initialvalue] Dim variable[, variable2 [, variable3]] [As type] [Alias othervar [, othervar2]] [= initialvalue] Dim variable[, variable2 [, variable3]] [As type] [At location] [= initialvalue] For Arrays: Dim array(size) [As type] [At location] For Strings: Dim string [* size] [At location]
Explanation:
The Dim command is used to declare variables, arrays, and strings. It can also create aliases for existing variables or place variables
at specific memory locations.
GCBASIC supports optional initialisation at the point of declaration:
Dim byte_var As Byte = 1
This sets the variable to the specified value at program start. The traditional form remains fully valid:
Dim byte_var As Byte
If no initial value is provided, the starting state of the variable depends on the target chip family. Do not assume a variable starts at zero unless you have explicitly initialised it or confirmed your target is in the "initialised to zero" category below.
| Chip Family | Behaviour without an initial value |
|---|---|
|
AVR Dx (e.g. AVR128DA, AVR64DB, etc.) |
Initialised to zero |
|
LGT (LGT8F series) |
Initialised to zero |
|
All other supported chips (PIC, classic/early AVR, etc.) |
Unknown/undefined state — the variable holds whatever value was already present in memory (e.g. left over from a previous program, or the power-on state of RAM) until your program explicitly sets it |
Command Availability: Available on all microcontrollers.

