Menu

Why no error flag?

Help
Paul Haug
2017-03-03
2017-03-03
  • Paul Haug

    Paul Haug - 2017-03-03

    Why when I asm or hex this source file, no error shows up. Note the DataCount value is messed up.
    I am using some sample codes to learn how to use and how the compiler reacts to illigal syntax or values, and what it does with them.
    Syntax errors show up.
    Using V 0.97.0

     'Stop program when EEPROM is full
     If DatacCount = 2abc55 then
      Set FullLight On  'Turn on the light
      End     'End the program
     End If
     .
    

    This is just a snippit of the original source code that compiles fine without the intended error.

     

    Last edit: Paul Haug 2017-03-03
  • Paul Haug

    Paul Haug - 2017-03-03

    Using V 0.97.00
    .
    Sorry, just figured out how to edit above, I'll get there.

     

    Last edit: Paul Haug 2017-03-03
  • Anobium

    Anobium - 2017-03-03

    Error flag. Do you mean a type error? Or, something else?

     
  • Paul Haug

    Paul Haug - 2017-03-03

    I am wondering why the GCB compiler does not flag a error on the statement containg an obvious (to me) value that is not a value within the bounds of a number 0-255 ?
    Such as what is in the above example listing snippit *= 2abc55 *

     

    Last edit: Paul Haug 2017-03-03
  • William Roth

    William Roth - 2017-03-04

    Since 2abc55 is not a valid number the compiler assumes you meant to it to be a variable and sets aside a memory location for a variable named 2abc55. You can see this bye opening the ASM and looking at the variable section. ( Open ASM with Shift + F7)

    This is partly why #Option Explicit was added. Option explicit requires that all variables in source code be explicitly declared with a DIM statement. Then these kind of errors are easily caught by the compiler.

    If 2abc55 was ment to be a hex value then the "0x" Prefix need to be used eg. 0x2abc55

    So try to compile the code below and see what happens. Then remove "option explicit" and change the number to 0x2abc55 and see what happens.

    I recommend using option explict as a matter of habit.

     #Chip 16F1847, 32
     #Config OSC = INTOSC, MCLRE = OFF, WDTE = OFF
    
     #Option Explicit    '// ADDED 
     #define FullLight PORTA.0
     DIM Datacount as LONG  ' very large number 
    
    Do
          Datacount++
          If DatacCount = 2abc55 then
               Set FullLight On  'Turn on the light
              End     'End the program
          End If
    Loop
    
     

    Last edit: William Roth 2017-03-04
  • Paul Haug

    Paul Haug - 2017-03-04

    Thanks, just what I needed. I now remember fainty reading about #Option Explicit
    Again, thanks.
    Makes perfect sense the way you explained it.
    Will also remember to add your #config statement, great reminder.....

     

    Last edit: Paul Haug 2017-03-04

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.