Menu

Not a bug, just subtle to me; code compiles fine, but assembler says the declared variables are not found

R. G. Keen
2026-01-11
2026-01-12
  • R. G. Keen

    R. G. Keen - 2026-01-11

    I spent some hours tracking this down. As usual, it was my incomplete understanding of this setup and the error messages.
    I always carefully define my variables and aliases, never relying on the IDE to just make them up for me. I also like to declare bytes and aliases for the bits I use as conditions. Sure, the compiler would probably do it for me, but I like them explicitly being in one place.
    Upon a minor change to the code, it continued to compile fine, but gave me assembler errors saying that the bit aliases I was using were not declared. Of course they were declared, I do that FIRST.
    The help documentation recommends this:

        Dim SerialByte As Byte
        #Define StatusReady  SerialByte.0
        #Define StatusError  SerialByte.1
        #Define StatusMotor  SerialByte.2
        #Define StatusOkBut  SerialByte.3
        #Define StatusUpBut  SerialByte.4
        #Define StatusDnBut  SerialByte.5
        #Define StatusLeBut  SerialByte.6
        #Define StatusRiBut  SerialByte.7
    
        SerialByte = 0                 // This will address the specific byte
    

    And it works fine, of course. But if you ever fail to do that last assignment of SerialByte = 0 (or really, any value of any bit there)) it still compiles, but the assembler will throw errors on any use of any alias.

    Of course it does - the compiler optimizes unused variables out of the code, and does not catch that the defines and references to the aliases amount to a "use" so there is no symbol left for the assembler to work on, One of my code tinkers removed the assignment of the byte, and there were no other assignments of bits until I tried to use them.

    I had sloppily not followed another of my normal practices: always explicitly set every variable to a starting value. I bet this has caught others.

     
  • Anobium

    Anobium - 2026-01-12

    :-) You will enjoy the next release. When you define the variable you can initialise it.

    Dim SerialByte As Byte = 0


    What is "One of my code tinkers removed the assignment of the byte "?

     
  • R. G. Keen

    R. G. Keen - 2026-01-12

    I looked for that! Thank you!

     

Log in to post a comment.

MongoDB Logo MongoDB