Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
MPLAB
®
XC16 C COMPILER
USERS GUIDE
2012-2013 Microchip Technology Inc. DS50002071C-page 171
Chapter 11. Operators and Statements
11.1 INTRODUCTION
The MPLAB XC16 C Compiler supports all the ANSI operators. The exact results of
some of these are implementation defined and this behavior is fully documented in
Appendix A. Implementation-Defined Behavior. The following sections illustrate
code operations that are often misunderstood as well as additional operations that the
compiler is capable of performing.
Built-In Functions
Integral Promotion
11.2 BUILT-IN FUNCTIONS
Built-in functions give the C programmer access to assembler operators or machine
instructions that are currently only accessible using inline assembly, but are sufficiently
useful that they are applicable to a broad range of applications. Built-in functions are
coded in C source files syntactically like function calls, but they are compiled to
assembly code that directly implements the function, and usually do not involve func-
tion calls or library routines.
For more on built-in functions, see Appendix G. Built-in Functions.
11.3 INTEGRAL PROMOTION
When there is more than one operand to an operator, they typically must be of exactly
the same type. The compiler will automatically convert the operands, if necessary, so
they do have the same type. The conversion is to a larger type so there is no loss of
information; however, the change in type can cause different code behavior to what is
sometimes expected. These form the standard type conversions.
Prior to these type conversions, some operands are unconditionally converted to a
larger type, even if both operands to an operator have the same type. This conversion
is called integral promotion and is part of Standard C behavior. The compiler performs
these integral promotions where required, and there are no options that can control or
disable this operation. If you are not aware that the type has changed, the results of
some expressions are not what would normally be expected.
Integral promotion is the implicit conversion of enumerated types, signed or
unsigned varieties of char, short int or bit-field types to either signed int or
unsigned int. If the result of the conversion can be represented by an signed int,
then that is the destination type, otherwise the conversion is to unsigned int.
Consider the following example.
unsigned char count, a=0, b=50;
if(a - b < 10)
count++;
The unsigned char result of a - b is 206 (which is not less than 10), but both a and
b are converted to signed int via integral promotion before the subtraction takes
place. The result of the subtraction with these data types is -50 (which is less than 10)
and hence the body of the if() statement is executed.
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf