Anobium - 2022-08-11

You can now redefine constants to improve program logic and to make your program easier to understand.

In the past you could not redefine a constant and this has led to many workarounds using scripts and/or a complex set of variables.

Now you have a new directive to delete an existing constant permitting you to redefine the same constant.

#UNDEFINE

The #UNDEFINE directive removes the current definition of a constant. Consequently, subsequent occurrences of constant are ignored by the preprocessor.

This is the same as #undef in other compilers.

Usage

The following program shows the use of #UNDEFINE and the #DEFINE to change the value of a constant based upon some program logic.

The program shows the control of the constant ORANGE.
1. Initialised as 0
2. Set to 1 if the constant __VAR exists
3. Set to 2 if the constant __VAR does not exists
.

#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

This is a very different behaviour from previous releases of the compiler, Previously the compiler would have set ORANGE to 0 and all other attempts to change would have failed silently.

The behaviour of having to use #UNDEFINE matches other compilers and is makes usage consistent.

Warnings

The warning messages are show if the file is the 'master' program source or an #include file contains #OPTION USERINCLUDE

This is a new directive to instruct the pre-processor portion of the compiler to replace constants without issuing an error message.

To stop the warnings from being issued - use the constant IGNORECONSTANTASSIGNMENTWARNINGS.

#DEFINE IGNORECONSTANTASSIGNMENTWARNINGS

This change makes the compiler consistent and removes silent errors.

Enjoy

 

Last edit: Anobium 2022-08-11