Anobium - 2022-08-11

Debugging IDEFs statement was a black art for advanced developers.

There is now a method to display the IFDEFs that will be processed. The method will show for a specific file and this display will help you understand the process that the compiler will take to determine the results of conditional processing.

An Example

The base program. The constant __VAR is the condition - if is exists then the constant ORANGE =1 else ORANGE = 2.

#CHIP 16F88
#OPTION EXPLICIT

#DEFINE __VAR

#DEFINE ORANGE 0      'Set to zero to prove conditional processing works!!

Dim ByteVar as  Byte
ByteVar = 255

#IFDEF __VAR
    #UNDEFINE ORANGE
    #DEFINE ORANGE 1    'New constant value
    ByteVar=99          'To show code is executing
#ELSE
    #UNDEFINE ORANGE
    #DEFINE ORANGE 2     'New constant value   
    ByteVar=98           'To show code is executing
#ENDIF

ByteVar = ORANGE        'Assign constant to a variable

With the debugger active the follow information is displayed. This shows the process - lines 11 thru 14 will be executed.

  11: #IFDEF __VAR
  12: #UNDEFINE ORANGE
  13: #DEFINE ORANGE 1
  ;ByteVar=99          'To show code is executing
  14: BYTEVAR=99

If the constant __VAR is commented out then the following debug is shown.

  15: #IFNDEF __VAR
  16: #UNDEFINE ORANGE
  17: #DEFINE ORANGE 2
  ;ByteVar=98           'To show code is executing
  18: BYTEVAR=98

This example shows the power of the debugger.


How to enable

As this is an in advanced capability the only was to enable it via the compiler ini/setup file.

Add to the [gcbasic] section of the ini file the item conditionaldebugfile with the parameter of the filename to debug.

[gcbasic]
conditionaldebugfile = showifdefsdebug.gcb


This will help those trying to use conditional IFDEFs

Enjoy