CONSTANTS

CONSTANTS

 

1) Numerical Constants

Expressing numerical constants in decimal (base 10) or hexadecimal (base 16)
are the same as in C.  To express a numerical constant in binary (base 2)
notation, the sequence of 1's and 0's are preceded by 0b, with no spaces in
between.  To express a numerical constant in octal (base 8) notation, the
sequence of octal digits (0 to 7) are preceded by 0o with no spaces.

Some examples:
    0b11111111     // same as 255
    0x00F          // same as 15
    0o10           // same as 8

2)  Character Constants

Single character constants are, like in C, enclosed in single quotes (').
Also as in C, special characters are expressed by a back slash (\) followed
by the key letter or letters.  Special characters supported are:
    '\a'    same as in C
    '\b'     beep 
    '\f'     form feed 
    '\l'    line feed 
    '\n'   carrage return
    '\r'    carrage return
    '\t'    tab
    '\x??'  ASCII character formed from the ?? which would be two
           hexadecimal digits for the character value
    '\???'  ASCII character formed from the ??? which would be three
           decimal digits for the character value
Any other character following a back slash is just accepted.  This allows
the single quote to be included by '\'', for '' is the NULL character.

Multiple character constants are also supported by C--.  Some examples of
multiple character constants are:

    'ab'
    'the'
    'this is large'

There is no limit to the number of characters in a character constant, but
only the last 4 characters are significant.  This is the maximum that can be
stored in a 32 bit variable.  For example, 'this is large' would be
equivalent to 'arge'.

C-- treats all character constants as a numeric value of the ASCII value of
the character.  For multiple character constants, the first character is the
most significant, thus the value for 'ab' is 'a'*256+'b'.

3)  String Constants

String constants, like in C, are inclosed in double quotes (").  Special
characters are expressed within strings the same way as in character
constants.  All the special characters are the same as in character constants
with the exception of \n which inserts both a carrage return and a line feed.

The current maximum length of string constants is 1000 including the 0
terminator, thus a maximum of 999 characters.

4)  Constant Expressions

A constant expression is single numerical constant or a list of numerical
constants linked together by operators which are evaluated at compile time to
a single constant value.

Like all expressions in C--, constant expressions are always evaluated from
left to right, regardless of operations!  This is quite different that most
other languages, and care must be used to remember that 2 + 3 * 2 = 10 and
not 8.

All numerical values in C-- are integer values.

Some examples of constant expressions are:
45 & 1 + 3         // equals 4
14 - 1 / 2         // equals 6 (remember integer values)
1 * 2 * 3 / 2 + 4  // equals 7


Post a Comment

0 Comments