2.5. Constants

2.5.1. Unnamed Constants

An unnamed numeric constant has the type UNIVERSAL, which is a 32-bit signed value. When a value of type UNIVERSAL is used in an operation, it is converted to the type of the other operand.

An exception to above is floating point constants have type FLOAT.

Numeric constants have the following formats:

12 -- decimal
0x12 -- hexadecimal
0b01 -- binary
0q01 -- octal
"a" -- ASCII
1.23 or 1.23e2 or 1.23e-2 -- FLOAT

An ASCII constant evaluates to the first character except when used to initialize a constant or variable array in which case each character is used as one entry.

The full format of a floating point constant is:


For example:

            VAR BYTE ch = "123"    ' ch is set to '1'
            VAR BYTE str[] = "123" ' str[0] is set to '1'
                                   ' str[1] is set to '2'
                                   ' str[2] is set to '3'

An ASCII constant allows the C language escaping rules as follows:

Table 2-2. ASCII Constant Escaping

Sequence Value
"\ooo" octal constant
"\a" bell
"\b" backspace
"\f" formfeed
"\n" line feed
"\qooo" octal constant
"\r" carriage return
"\t" horizontal tab
"\v" vertical tab
"\xdd" hexidecimal constant
"\zbbb" "binary constant"
"\\" A single '\'

constants other than ASCII constants may also contain any number of underscores ("_") which are ignored, but are useful for grouping. For example: 0b0000_1111

2.5.2. Named Constants

The complete format for defining a named constant is:

          CONST [type[*cexpr]] identifier [ '[' [ cexpr ] ']' ]
            '=' { cexpr | '{' cexpr1[',' cexpr2...]'}' | '"'...'"'}
            [ ',' identifier2...]


CONST denotes the beginning of a constant definition clause.


Defines the type of the constant. If none is given, the constant becomes universal type which is 32 bit signed.

'[' [ cexpr ] ']'

Defines a constant array (see array variable types). A constant array will not take any space unless it is indexed at least once with a non-constant subscript. On the PIC, constant arrays consume *code* space, not *data* space, and are limited to 255 elements.

If cexpr is ommitted, the size of the array will be determined by the number of initializers used.

'=' cexpr

For non-array constants this assigns the value to the constant

'=' '{' cexpr[',' cexpr2...] '}'

For arrays of constants this assigns the value to each element. There must be the same number of cexprs as there are elements defined.

'=' '"' ... '"'

For an array of constants, this assigns each ASCII value between '"' and '"' to one element of the constant array. Unlike C, there is no terminating NUL.

2.5.3. String Literals (introduced with JALv2.4p)

String literals are enclosed in quotation markes '"'...'"' and can be used where ever an array of characters is allowed. The ASCII constant escaping noted under, `Unnamed Constants,' applies to each characterw within the string literal.

Note that a string literal terminates with the first NUL characters (0x00).