Special constants behaviors

Language reference ›› Constants ››
Parent Previous Next

The only math operator allowed between STRING constants is +. String construction with implicit concatenation is not allowed (TP / Delphi syntax like 'hello'^M^J'world!'). Anything that is not a string is converted to a single char (numeric 10 is converted to LF character).

A constant string is implemented as ARRAY[0..SIZEOF(<constant-string>)-1] OF BYTE, the first byte at index 0 stores the string length as for a variable string.

Except for strings or arrays, a symbol of type constant does not consume RAM space; they are only used by the compiler. 

Contrary to rules used by TP or Delphi, a typed constant is not modifiable at runtime (it is not in RAM). 

Constant strings and arrays are stored in program code space (use of a set of RETLW instructions for PIC10..PIC16 and DATA directives for PIC18+). PMP tries to optimize constant strings or arrays if they are short or indexed by a constant (can generate no code space at all for the data).

If a string is only referenced with a constant index (S[constant]) it will not generate a block of code for storing the constant string.

A small enough string move (assignment) is implemented as individual byte moves.

If a constant string is used more than once it will generate only one block of code to store it.


Characters of a string may be accessed through an index like for an ARRAY:

 


CONST
  MyString = 'Hello ' + 'World!' + 13 + 10;
  
  A := MyString[TheIndex];