Menu

Byte needs DIM with #OPTION EXPLICIT?

2025-03-08
2025-03-09
  • Roger Jönsson

    Roger Jönsson - 2025-03-08

    GC compiler terminal: "Error: Variable xxx was not explicitly declared. "

    This text added to my confusion saying that bytes shouldn't need dimensioning(?):
    "Byte variables do not need any special commands to set them up - just put the name of the variable in to the command where the variable is needed.
    Other types of variable can be used in a very similar way, except that they must be "dimensioned" first. This involves using the DIM command, to tell GCBASIC that it is dealing with something other than a byte variable."
    https://gcbasic.sourceforge.io/help/_variable_types.html

    I now realise that this has changed with #OPTION EXPLICIT.
    Maybe the quoted text needs editing or am I misunderstanding things?

     

    Last edit: Roger Jönsson 2025-03-08
  • Anobium

    Anobium - 2025-03-09

    @Roger.

    I have updated the Help. You point is valid and the Help needed updating.

    Using Variables

    Byte variables do not need any special commands to set them up - just put the name of the variable in to the command where the variable is needed. However, it is good practice to "dimension" all byte variables and to use #OPTION EXPLICiT. #OPTION EXPLICiT mandates the "dimensioning" of all variables in the user program. Using #OPTION EXPLICiT will improve the quality of the program.

    Other types of variable can be used in a very similar way, except that they must be "dimensioned" first. This involves using the DIM command, to tell GCBASIC that it is dealing with something other than a byte variable.

    A key feature of variables is that it is possible the have the microcontroller check a variable, and only run a section of code if it is a given value. This can be done with the IF command.

    Number Variables

    You can assign values to number variables using  =.

    A simple, but typical example follows. This is the typical for numeric variable assignment.

    #OPTION EXPLICIT
    
    dim myByteVarible as Byte
    myByteVarible = 127       'assign the value of 127
    

    The actual source is here: https://github.com/GreatCowBASIC/Help/blob/main/source/variables.adoc

    Evan

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.