Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About constants
#2
LCD Wrote:Defining constants with CONST Constant as UByte=0 is not the ideal way, because they can be easy mistaken for variables, and can interfer with variables. So my proposal is to change it to similar way, PureBasic does:
#Constant as UByte=0, and all constants are marked with "#" sign in the front. In PureBasic it is a little different, as the constant and variable types are defined this way: #constant.ub=0 (ub=short for unsigned byte, has to be defined only one time).
apart from this I propose to include build-in constants with ROM Labels and System variables:
#KSTATE=23552, #LASTK=23560, #REPDEL=23561, #REPPER=23562, ...
#start=$0, #error_1=$8, #print_a_1=$10, #get_char=$18
#test_char=$1C, #next_char=$20, #fp_calc=$28, #bc_spaces=$30, ...
Also constants for some other usages:
#False=0, #True=1, #Zero=0
#Black=0, #Blue=1, #Red=2, #Magenta=3,...

Is this a good idea???

Hi, LCD

Well, I'm following the FreeBasic standard. Basically, you can use CONST, or #define. CONST creates a TYPED constant, whilst #define just define a macro (that is, replace a word with another).

The example you give above for PureBasic is a Macro. You can use them if you feel more comfortable with them. This way:
Code:
#define True 1
#define False 0
Notice you always use #define with no equal sign (=). This will give you the same result as PureBasic. You can also elaborate more complex macros:

Code:
#define square(x)  (x * x)
PRINT "Square of 5 is "; square(5) : REM Square is an Inline function.

Note: ZX Basic admits hexadecimal numbers with $-prefix (as you use) or with h-suffix. Eg. 32 (decimal) => $20 or 20h

BTW: Nice retro-site! :!: 8)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)