Symbols for constants with arithmetic, PE6

cpedw

Senior Member
When I set a value for a constant using Symbol, the value is displayed (after syntax check) if the mouse hovers over the name. If the constant involves arithmetic, the value displayed is just the name of the symbol on the right of the calculation. This short code shows the effect: hovering over numtl1 shows HOWMANYLEDS but hovering over HOWMANYLEDS shows 128 and other versions of the true value

Code:
Symbol HOWMANYLEDS = 128
symbol numtl1=HOWMANYLEDS - 1
symbol numtl2=numtl1 / 64

b0=numtl2
b1=numtl1
If the hovering is done during a break in the simulation, hovering over these constant names doesn't show anything.

I think it would be useful if these calculated constants showed their true values and if they could all show their values in the simulator.

Incidentally, i would also find it useful to be able to include more than one step of arithmetic when giving a value for a symbol. In the above example, I don't need numtl1 so it would be good to be allowed to write
Symbol numtl2=HOWMANYLEDS - 1`/ 64

Any chance of making these changes to PE6?

Derek
 

PieM

Senior Member
Incidentally, i would also find it useful to be able to include more than one step of arithmetic when giving a value for a symbol. In the above example, I don't need numtl1 so it would be good to be allowed to write
Symbol numtl2=HOWMANYLEDS - 1`/ 64

Derek
Code:
Symbol HOWMANYLEDS = 128
#define numtl2 HOWMANYLEDS - 1 / 64

b0=numtl2
 

AllyCat

Senior Member
Hi,

Incidentally, i would also find it useful to be able to include more than one step of arithmetic when giving a value for a symbol. In the above example, I don't need numtl1 so it would be good to be allowed to write
Symbol numtl2=HOWMANYLEDS - 1 / 64
Yes I agree that the restriction to a single operator in a symbol declaration can be really annoying, when trying to avoid the use of "magic numbers" in a program. You can of course write it in multiple lines (with additional intermediate variable names) but that affects the readability and convenience (which surely is the main point of using symbol declarations).

But I don't think that the #define helps (me) because that preprocessor directive simply inserts the code for "HOWMANYLEDS - 1 / 64" into the program, whilst the symbol directive would insert only the value of "HOWMANYLEDS - 1 / 64" into the program. Maybe not significant for most programs, but it can be if speed or program space are important, or when working through a simulator session.

Cheers Alan.
 

hippy

Technical Support
Staff member
The hover-over issue has been noted. The single operator restriction in SYMBOL is a long standing feature and is also noted.

As PieM notes, and AllyCat comments upon, #DEFINE can be usefully used to have more than one operator but the caveat is it becomes a source code substitution so that more memory may be used and there will be syntax errors if the #DEFINE name appears where only a single variable or number can be used ...

Code:
Symbol Maximum  = 10
Symbol Minimum  = 5
Symbol Range    = Maximum - Minimum
Symbol Quantity = Range + 1
SerTxd( "There are ", #Quantity, " values between ", #Minimum, " and ", #Maximum, " inclusive" )
Code:
#Define Maximum  10
#Define Minimum  5
#Define Range    Maximum - Minimum
#Define Quantity Range + 1
SerTxd( "There are ", #Quantity, " values between ", #Minimum, " and ", #Maximum, " inclusive" )
Using "Let b0 = Quantity" works in both cases, but #DEFINE will use more code -

For SYMBOL : Let b0 = 6
For #DEFINE : Let b0 = 10 - 5 + 1
 
Top