# Vault 7: Projects

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

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 117
- 118
- 119
- 120
- 121
…
- 365
- 366

Supported Data Types and Variables
 2012-2013 Microchip Technology Inc. DS50002071C-page 119
8.6 STRUCTURES AND UNIONS
MPLAB XC16 C Compiler supports struct and union types. Structures and unions
only differ in the memory offset applied to each member.
These types will be at least 1 byte wide. Bit-fields are fully supported in structures.
Structures and unions may be passed freely as function arguments and function return
values. Pointers to structures and unions are fully supported.
Implementation-defined behavior of structures, unions and bit-fields is described in
Section A.10 Structures, Unions, Enumerations and Bit-Fields.
8.6.1 Structure and Union Qualifiers
The MPLAB XC16 C Compiler supports the use of type qualifiers on structures. When
a qualifier is applied to a structure, all of its members will inherit this qualification. In the
following example, the structure is qualified const.
const struct foo {
int number;
int *ptr;
} record = { 0x55, &i };
In this case, the entire structure may be placed into the program space where each
member will be read-only. Remember that all members are usually initialized if a
structure is const as they cannot be initialized at runtime.
If the members of the structure were individually qualified const, but the structure was
not, then the structure would be positioned into RAM, but each member would be still
be read-only. Compare the following structure with the one above.
struct {
const int number;
int * const ptr;
} record = { 0x55, &i};
8.6.2 Bit-fields in Structures
The MPLAB XC16 C Compiler fully supports bit-fields in structures.
Bit-fields are, by default, signed int. They may be made an unsigned int
bit-field by using a command line option, see Section 5.7.3 Options for Con-
trolling the C Dialect.
The first bit defined will be the LSb of the word in which it will be stored.
The compiler supports bit-fields with any bit size, up to the size of the underlying type.
Any integral type can be made into a bit-field. The allocation does not normally cross a
bit boundary natural to the underlying type.
For example:
struct foo {
long long i:40;
int j:16;
char k:8;
} x;
struct bar {
long long I:40;
char J:8;
int K:16;
} y;

- 1
- 2
…
- 117
- 118
- 119
- 120
- 121
…
- 365
- 366