There are four types of constant values that can be used in the source code of the TE language:
Decimal Integer constants
Hexadecimal Integer constants
String constants
Predefined constant identifiers.
Decimal integers can be used wherever a rvalue is valid (E.g. in expressions and assignments. These numbers may optionally be prefixed with a + or – sign, for example:
a=123;
b=+47+12;
c=-123456576;
Decimal number constants are converted to null terminated ASCII strings before they are stored or used by the TE language.
Similarly hexadecimal integers can be used wherever a rvalue is valid and must be prefixed with the characters 0x, for example:
a=0xff;
b=0xEE7;
Either upper or lower case letters can be used in the hexadecimal number and the compiler will convert the values to a decimal numeric string before using or storing the value. Note that this is a compile time conversion and hexadecimal string values will NOT be converted at run-time. Therefore the following statements are not valid if you are assuming a will evaluate to decimal 15:
a= "0xf" // Compiler will not convert this as it’s a string
b=a+1; // This evaluates to 1 since "0xf" evaluates to 0
Since strings are evaluated as decimal values “0xf” will be evaluated as 0 since the first non-numeric character (‘x’ in this case) stops the conversion.
The difference between the following two statements should be understood:
a=0xf; // Compiler will convert to the decimal string "15"
b= "0xf"; // Compiler will store the string in quotes ‘as is’
//i.e "0xf" will be stored and any arithmetic operation
// or assignment to int type at run-time will
// evaluate this to "0"
string constants must be surrounded by double quotes and are stored in var types ‘as is’ without conversion. Here is an example of a string:
“this is a string”
Note however that if the var type is not long enough to hold the string then it will be truncated before storing in the variable. For int type variables or in arithmetic expressions the string will be converted to a numeric string before being stored or used.
Within a string a backslash character has special meaning and is known as an escape character since it allows non-printable an other special characters to be included in the string. The following esccape sequences are interpreted by the compiler as follows:
|
Sequence |
Puts this single character into the stored string |
|
\\ |
Single backwards character |
|
\q |
Double-quote " |
|
\r |
Carriage-return (hex 0A) |
|
\n |
New-line (hex 0D) |
|
\t |
Tab (hex 09) |
|
\xx |
Byte with hex value xx, eg \09 would have the same effect as \t. It is illegal to use `00. |
Predefined constant identifiers are constant that have been defined using the const declaration in a declaration_block. For example, if the following constants will all evaluate to the same string “255” and can be used anywhere that an rvalue is valid.
// All three of these constants will evaluate to the same sting: “255”
const a=255;
const b=0xff;
const c= "255";
...
total=a+b+c; // = 255+255+255