A character constant is one or more characters enclosed in single quotes, such as
In the mikroC PRO for PIC32, single-character constants are of the
unsigned int type. Multi-character constants are referred to as string constants or string literals. For more information refer to String Constants.
A backslash character (
\) is used to introduce an escape sequence, which allows a visual representation of certain nongraphic characters. One of the most common escape constants is the newline character (
A backslash is used with octal or hexadecimal numbers to represent an ASCII symbol or control code corresponding to that value; for example,
'\x3F' for the question mark.
Any value within legal range for data type char (
0xFF for the mikroC PRO for PIC32) can be used.
Larger numbers will generate the compiler error “Out of range”.
For example, the octal number
\777 is larger than the maximum value allowed (
\377) and will generate an error. The first nonoctal or nonhexadecimal character encountered in an octal or hexadecimal escape sequence marks the end of the sequence.
The following table shows the available escape sequences:
|Sequence||Value||Char||What it does|
|\'||0x27||'||Single quote (Apostrophe)|
|\O||any||O = string of up to 3 octal digits|
|\xH||any||H = string of hex digits|
|\XH||any||H = string of hex digits|
Some ambiguous situations might arise when using escape sequences.
Here is an example:
This is intended to be interpreted as
"1.0 Intro". However, the mikroC PRO for PIC32 compiles it as the hexadecimal number
\x091 and literal string
".0 Intro". To avoid such problems, we could rewrite the code in the following way:
Lcd_Out_Cp("\x09" "1.0 Intro");
For more information on the previous line, refer to String Constants.
Ambiguities might also arise if an octal escape sequence is followed by a nonoctal digit. For example, the following constant:
would be interpreted as a two-character constant made up of the characters
8 is not a legal octal digit.
What do you think about this topic ? Send us feedback!