# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 123
- 124
- 125
- 126
- 127
…
- 365
- 366

Supported Data Types and Variables
 2012-2013 Microchip Technology Inc. DS50002071C-page 125
Here is an example of code that may fail because the default type assigned to a literal
constant is not appropriate:
unsigned long int result;
unsigned char shifter;
void main(void)
{
shifter = 20;
result = 1 << shifter;
// code that uses result
}
The literal constant 1 will be assigned an int type; hence the result of the shift opera-
tion will be an int and the upper bits of the long variable, result, can never be set,
regardless of how much the literal constant is shifted. In this case, the value 1 shifted
left 20 bits will yield the result 0, not 0x100000.
The following uses a suffix to change the type of the literal constant, hence ensure the
shift result has an unsigned long type.
result = 1UL << shifter;
Floating-point literal constants have double type unless suffixed by f or F, in which
case it is a float constant. The suffixes l or L specify a long double type. In
MPLAB XC16, the double type equates to a 32-bit float type. The command line
option, -fno-short-double, may be use to specify double as a 64-bit long
double type.
Fixed-point literal constants look like floating point numbers, suffixed with combinations
of [u][h,l]<r,k>. The suffix u means unsigned. The suffixes h and l signify short and
long respectively. The suffix r denotes a _Fract type and k specifies an _Accum type.
So for example, -1.0r is a signed _Fract and 0.5uhk is an unsigned short _Accum.
Character literal constants are enclosed by single quote characters, , for example
a. A character literal constant has int type, although this may be optimized to a
char type later in the compilation.
Multi-byte character literal constants are supported by this implementation.
String constants, or string literals, are enclosed by double quote characters ", for exam-
ple "hello world". The type of string literal constants is const char * and the
character that make up the string may be stored in the program memory.
To comply with the ANSI C standard, the compiler does not support the extended char-
acter set in characters or character arrays. Instead, they need to be escaped using the
backslash character, as in the following example:
const char name[] = "Bj\xf8k";
printf("%s's Resum\xe9", name); \\ prints "Bjørk's Resumé"
Defining and initializing a non-const array (i.e. not a pointer definition) with a string,
for example:
char ca[]= "two"; // "two" different to the above
is a special case and produces an array in data space which is initialized at startup with
the string "two", whereas a string literal constant used in other contexts represents an
unnamed array, accessed directly from its storage location.
The compiler will use the same storage location and label for strings that have identical
character sequences, except where the strings are used to initialize an array residing
in the data space as shown in the last statement in the previous example.
Two adjacent string literal constants (i.e. two strings separated only by white space) are
concatenated by the C preprocessor. Thus:
const char * cp = "hello " "world";

- 1
- 2
…
- 123
- 124
- 125
- 126
- 127
…
- 365
- 366