Character Constants

A character constant is one or more characters enclosed in single quotes, such as 'A', '+', or '\n'. 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.

Escape Sequences

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 (\n).

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 (0 to 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.

  Note : You must use the sequence \\ to represent an ASCII backslash, as used in operating system paths.

The following table shows the available escape sequences:

Sequence Value Char What it does
\a 0x07 BEL Audible bell
\b 0x08 BS Backspace
\f 0x0C FF Formfeed
\n 0x0A LF Newline (Linefeed)
\r 0x0D CR Carriage Return
\t 0x09 HT Tab (horizontal)
\v 0x0B VT Vertical Tab
\\ 0x5C \ Backslash
\' 0x27 ' Single quote (Apostrophe)
\" 0x22 " Double quote
\? 0x3F ? Question mark
\O any O = string of up to 3 octal digits
\xH any H = string of hex digits
\XH any H = string of hex digits

Disambiguation

Some ambiguous situations might arise when using escape sequences.

Here is an example:

Lcd_Out_Cp("\x091.0 Intro");

This is intended to be interpreted as \x09 and "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:

"\118"

would be interpreted as a two-character constant made up of the characters \11 and 8, because 8 is not a legal octal digit.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code