MPLAB C Compiler
MPLAB C Compiler
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Table of Contents
Preface ........................................................................................................................... 1
Chapter 1. Compiler Overview
1.1 Introduction ..................................................................................................... 7
1.2 Highlights ........................................................................................................ 7
1.3 Compiler Description and Documentation ...................................................... 7
1.4 Compiler and Other Development Tools ........................................................ 8
1.5 Compiler Feature Set ..................................................................................... 9
Chapter 2. Differences Between 16-Bit Device C and ANSI C
2.1 Introduction ................................................................................................... 11
2.2 Highlights ...................................................................................................... 11
2.3 Keyword Differences .................................................................................... 11
2.4 Statement Differences .................................................................................. 30
2.5 Expression Differences ................................................................................ 32
Chapter 3. Using the Compiler on the Command Line
3.1 Introduction ................................................................................................... 33
3.2 Highlights ...................................................................................................... 33
3.3 Overview ...................................................................................................... 33
3.4 File Naming Conventions ............................................................................. 34
3.5 Options ......................................................................................................... 34
3.6 Environment Variables ................................................................................. 59
3.7 Predefined Macro Names ............................................................................. 60
3.8 Compiling a Single File on the Command Line ............................................ 60
3.9 Compiling Multiple Files on the Command Line ........................................... 61
3.10 Notable Symbols ........................................................................................ 62
Chapter 4. Run Time Environment
4.1 Introduction ................................................................................................... 63
4.2 Highlights ...................................................................................................... 63
4.3 Address Spaces ........................................................................................... 63
4.4 Startup and Initialization ............................................................................... 64
4.5 Memory Spaces ........................................................................................... 65
4.6 Memory Models ............................................................................................ 66
4.7 Locating Code and Data ............................................................................... 68
4.8 Software Stack ............................................................................................. 69
4.9 The C Stack Usage ...................................................................................... 70
4.10 The C Heap Usage ..................................................................................... 72
4.11 Function Call Conventions ......................................................................... 73
4.12 Register Conventions ................................................................................. 75
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE on-line help.
Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs. Items discussed include:
• Document Layout
• Conventions Used in this Guide
• Recommended Reading
• The Microchip Web Site
• Development Systems Customer Change Notification Service
• Customer Support
DOCUMENT LAYOUT
This document describes how to use GNU language tools to write code for 16-bit
applications. The document layout is as follows:
• Chapter 1: Compiler Overview – describes the compiler, development tools and
feature set.
• Chapter 2: Differences between 16-Bit Device C and ANSI C – describes the
differences between the C language supported by the compiler syntax and the
standard ANSI-89 C.
• Chapter 3: Using the Compiler on the Command Line – describes how to use
the compiler from the command line.
• Chapter 4: Run Time Environment – describes the compiler run-time model,
including information on sections, initialization, memory models, the software stack
and much more.
• Chapter 5: Data Types – describes the compiler integer, floating point and pointer
data types.
• Chapter 6: Additional C Pointers – describes additional C pointers available.
• Chapter 7: Device Support Files – describes the compiler header and register
definition files, as well as how to use with SFR’s.
• Chapter 8: Interrupts – describes how to use interrupts.
• Chapter 9: Mixing Assembly Language and C Modules – provides guidelines to
using the compiler with 16-bit assembly language modules.
• Appendix A: Implementation-Defined Behavior – details compiler-specific
parameters described as implementation-defined in the ANSI standard.
• Appendix B: Built-in Functions – lists the built-in functions of the C compiler.
• Appendix C: Diagnostics – lists error and warning messages generated by the
compiler.
• Appendix D: MPLAB C Compiler for PIC18 MCUs vs. 16-Bit Devices – highlights
the differences between the PIC18 MCU C compiler and the 16-bit C compiler.
• Appendix E: Deprecated Features – details features that are considered
obsolete.
• Appendix F: ASCII Character Set – contains the ASCII character set.
• Appendix G: GNU Free Documentation License – usage license for the Free
Software Foundation.
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB® IDE User’s Guide
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog
A menu selection select Enable Programmer
Quotes A field name in a window or “Save project before build”
dialog
Underlined, italic text with A menu path File>Save
right angle bracket
Bold characters A dialog button Click OK
A tab Click the Power tab
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier font:
Plain Courier Sample source code #define START
Filenames autoexec.bat
File paths c:\mcc18\h
Keywords _asm, _endasm, static
Command-line options -Opa+, -Opa-
Bit values 0, 1
Constants 0xFF, ’A’
Italic Courier A variable argument file.o, where file can be
any valid filename
Square brackets [ ] Optional arguments mpasmwin [options]
file [options]
Curly brackets and pipe Choice of mutually exclusive errorlevel {0|1}
character: { | } arguments; an OR selection
Ellipses... Replaces repeated text var_name [,
var_name...]
Represents code supplied by void main (void)
user { ...
}
Icon
This feature supported only in
the full version of the soft-
ware, i.e., not supported in
academic or demo versions.
RECOMMENDED READING
This documentation describes how to use the MPLAB C Compiler for PIC24 MCUs and
dsPIC DSCs. Other useful documents are listed below. The following Microchip
documents are available and recommended as supplemental reference resources.
Readme Files
For the latest information on Microchip tools, read the associated Readme files (HTML
files) included with the software.
16-Bit Language Tools Getting Started (DS70094)
A guide to installing and working with the Microchip language tools for 16-bit devices.
Examples using the 16-bit simulator SIM30 (a component of MPLAB SIM) are
provided.
MPLAB® Assembler, Linker and Utilities for PIC24 MCUs and dsPIC® DSCs
User’s Guide (DS51317)
A guide to using the 16-bit assembler, object linker, object archiver/librarian and various
utilities.
16-Bit Language Tools Libraries (DS51456)
A descriptive listing of libraries available for Microchip 16-bit devices. This includes
standard (including math) libraries and C compiler built-in functions. DSP and 16-bit
peripheral libraries are described in Readme files provided with each peripheral library
type.
Device-Specific Documentation
The Microchip website contains many documents that describe 16-bit device functions
and features. Among these are:
• Individual and family data sheets
• Family reference manuals
• Programmer’s reference manuals
C Standards Information
American National Standard for Information Systems – Programming Language – C.
American National Standards Institute (ANSI), 11 West 42nd. Street, New York,
New York, 10036.
This standard specifies the form and establishes the interpretation of programs
expressed in the programming language C. Its purpose is to promote portability,
reliability, maintainability and efficient execution of C language programs on a
variety of computing systems.
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
1.2 HIGHLIGHTS
Items discussed in this chapter are:
• Compiler Description and Documentation
• Compiler and Other Development Tools
• Compiler Feature Set
C Source Files
(*.c)
Compiler
Driver
C Compiler
Program
Assembly Source
Files (*.s) Assembler
MPLAB® IDE
Debug Tool
Executable File
(*.exe)
Command-Line
Simulator
1.5.2 Optimization
The compiler uses a set of sophisticated optimization passes that employ many
advanced techniques for generating efficient, compact code from C source. The
optimization passes include high-level optimizations that are applicable to any C code,
as well as 16-bit device-specific optimizations that take advantage of the particular
features of the device architecture.
2.2 HIGHLIGHTS
Items discussed in this chapter are:
• Keyword Differences
• Statement Differences
• Expression Differences
address (addr)
The address attribute specifies an absolute address for the variable. This attribute
can be used in conjunction with a section attribute. This can be used to start a group
of variables at a specific address:
int foo __attribute__((section("mysection"),address(0x900)));
int bar __attribute__((section("mysection")));
int baz __attribute__((section("mysection")));
A variable with the address attribute cannot be placed into the auto_psv space (see
the space() attribute or the -mconst-in-code option); attempts to do so will cause
a warning and the compiler will place the variable into the PSV space. If the variable is
to be placed into a PSV section, the address should be a program memory address.
int var __attribute__ ((address(0x800)));
boot
This attribute can be used to define protected variables in Boot Segment (BS) RAM:
int __attribute__((boot)) boot_dat[16];
Variables defined in BS RAM will not be initialized on startup. Therefore all variables in
BS RAM must be initialized using inline code. A diagnostic will be reported if initial
values are specified on a boot variable.
An example of initialization is as follows:
int __attribute__((boot)) time = 0; /* not supported */
int __attribute__((boot)) time2;
void __attribute__((boot)) foo()
{
time2 = 55; /* initial value must be assigned explicitly */
}
deprecated
The deprecated attribute causes the declaration to which it is attached to be specially
recognized by the compiler. When a deprecated function or variable is used, the
compiler will emit a warning.
A deprecated definition is still defined and, therefore, present in any object file. For
example, compiling the following file:
int __attribute__((__deprecated__)) i;
int main() {
return i;
}
will produce the warning:
fillupper
This attribute can be used to specify the upper byte of a variable stored into a
space(prog) section.
For example:
int foo[26] __attribute__((space(prog),fillupper(0x23))) = { 0xDEAD };
will fill the upper bytes of array foo with 0x23, instead of 0x00. foo[0] will still be
initialized to 0xDEAD.
The command line option -mfillupper=0x23 will perform the same function.
far
The far attribute tells the compiler that the variable will not necessarily be allocated in
near (first 8 KB) data space, (i.e., the variable can be located anywhere in data
memory).
mode (mode)
This attribute specifies the data type for the declaration as whichever type corresponds
to the mode mode. This in effect lets you request an integer or floating point type
according to its width. Valid values for mode are as follows:
Mode Width Compiler Type
QI 8 bits char
HI 16 bits int
SI 32 bits long
DI 64 bits long long
SF 32 bits float
DF 64 bits long double
This attribute is useful for writing code that is portable across all supported compiler tar-
gets. For example, the following function adds two 32-bit signed integers and returns a
32-bit signed integer result:
typedef int __attribute__((__mode__(SI))) int32;
int32
add32(int32 a, int32 b)
{
return(a+b);
}
You may also specify a mode of byte or __byte__ to indicate the mode correspond-
ing to a one-byte integer, word or __word__ for the mode of a one-word integer, and
pointer or __pointer__ for the mode used to represent pointers.
near
The near attribute tells the compiler that the variable is allocated in near data space
(the first 8 KB of data memory). Such variables can sometimes be accessed more
efficiently than variables not allocated (or not known to be allocated) in near data
space.
int num __attribute__ ((near));
packed
The packed attribute specifies that a variable or structure field should have the
smallest possible alignment – one byte for a variable and one bit for a field, unless you
specify a larger value with the aligned attribute.
Here is a structure in which the field x is packed, so that it immediately follows a:
struct foo
{
char a;
int x[2] __attribute__ ((packed));
};
Note: The device architecture requires that words be aligned on even byte
boundaries, so care must be taken when using the packed attribute to
avoid run-time addressing errors.
persistent
The persistent attribute specifies that the variable should not be initialized or
cleared at startup. A variable with the persistent attribute could be used to store state
information that will remain valid after a device reset.
int last_mode __attribute__ ((persistent));
Persistent data is not normally initialized by the C run-time. However, from a
cold-restart, persistent data may not have any meaningful value. This code example
shows how to safely initialize such data:
#include "p24Fxxxx.h"
int main()
{
if ((RCONbits.POR == 0) &&
(RCONbits.BOR == 0)) {
/* last_mode is valid */
} else {
/* initialize persistent data */
last_mode = 0;
}
}
reverse (alignment)
The reverse attribute specifies a minimum alignment for the ending address of a
variable, plus one. The alignment is specified in bytes and must be a power of two.
Reverse-aligned variables can be used for decrementing modulo buffers in dsPIC DSC
assembly language. This attribute could be useful if an application defines variables in
C that will be accessed from assembly language.
int buf1[128] __attribute__ ((reverse(256)));
section ("section-name")
By default, the compiler places the objects it generates in sections such as .data and
.bss. The section attribute allows you to override this behavior by specifying that a
variable (or function) lives in a particular section.
struct array {int i[32];}
struct array buf __attribute__ ((section("userdata"))) = {0};
The section attribute conflicts with the address and reverse attributes. In both
cases, the section name will be ignored with a warning. This attribute may also conflict
with the space attribute. See the space attribute description for more information.
secure
This attribute can be used to define protected variables in Secure Segment (SS) RAM:
int __attribute__((secure)) secure_dat[16];
Variables defined in SS RAM will not be initialized on startup. Therefore all variables in
SS RAM must be initialized using inline code. A diagnostic will be reported if initial
values are specified on a secure variable.
String literals can be assigned to secure variables using inline code, but they require
extra processing by the compiler. For example:
char *msg __attribute__((secure)) = "Hello!\n"; /* not supported */
char *msg2 __attribute__((secure));
void __attribute__((secure)) foo2()
{
*msg2 = "Goodbye..\n"; /* value assigned explicitly */
}
In this case, storage must be allocated for the string literal in a memory space which is
accessible to the enclosing secure function. The compiler will allocate the string in a
psv constant section designated for the secure segment.
sfr (address)
The sfr attribute tells the compiler that the variable is an SFR and also specifies the
run-time address of the variable, using the address parameter.
extern volatile int __attribute__ ((sfr(0x200)))u1mod;
The use of the extern specifier is required in order to not produce an error.
Note: By convention, the sfr attribute is used only in processor header files. To
define a general user variable at a specific address use the address
attribute in conjunction with near or far to specify the correct addressing
mode.
Note: Variables placed in the auto_psv section are not loaded into data
memory at startup. This attribute may be useful for reducing RAM
usage.
int main()
{
DMA1STA = __builtin_dmaoffset(BufferA);
DMA1STB = __builtin_dmaoffset(BufferB);
/* ... */
}
transparent_union
This attribute, attached to a function parameter which is a union, means that the
corresponding argument may have the type of any union member, but the argument is
passed as if its type were that of the first union member. The argument is passed to the
function using the calling conventions of the first member of the transparent union, not
the calling conventions of the union itself. All members of the union must have the same
machine representation; this is necessary for this argument passing to work properly.
unordered
The unordered attribute indicates that the placement of this variable may move
relative to other variables within the current C source file.
const int __attribute__ ((unordered)) i;
unused
This attribute, attached to a variable, means that the variable is meant to be possibly
unused. The compiler will not produce an unused variable warning for this variable.
weak
The weak attribute causes the declaration to be emitted as a weak symbol. A weak
symbol may be superseded by a global definition. When weak is applied to a reference
to an external symbol, the symbol is not required for linking. For example:
extern int __attribute__((__weak__)) s;
int foo() {
if (&s) return s;
return 0; /* possibly some other value */
}
In the above program, if s is not defined by some other module, the program will still
link but s will not be given an address. The conditional verifies that s has been defined
(and returns its value if it has). Otherwise ‘0’ is returned. There are many uses for this
feature, mostly to provide generic code that can link with an optional library.
void foo() {
i = 1;
}
/* weak2.c */
int i;
extern void foo(void);
void bar() {
i = 2;
}
main() {
foo();
bar();
}
Here the definition in weak2.c of i causes the symbol to become a strong definition.
No link error is emitted and both i’s refer to the same storage location. Storage is
allocated for weak1.c’s version of i, but this space is not accessible.
There is no check to ensure that both versions of i have the same type; changing i in
weak2.c to be of type float will still allow a link, but the behavior of function foo will
be unexpected. foo will write a value into the least significant portion of our 32-bit float
value. Conversely, changing the type of the weak definition of i in weak1.c to type
float may cause disastrous results. We will be writing a 32-bit floating point value into
a 16-bit integer allocation, overwriting any variable stored immediately after our i.
In the cases where only weak definitions exist, the linker will choose the storage of the
first such definition. The remaining definitions become in-accessible.
The behavior is identical, regardless of the type of the symbol; functions and variables
behave in the same manner.
address (addr)
The address attribute specifies an absolute address for the function. This attribute
cannot be used in conjunction with a section attribute; the address attribute will take
precedence.
void __attribute__ ((address(0x100))) foo() {
...
}
Alternatively, you may define the address in the function prototype:
void foo() __attribute__ ((address(0x100)));
alias ("target")
The alias attribute causes the declaration to be emitted as an alias for another symbol,
which must be specified.
Use of this attribute results in an external reference to target, which must be resolved
during the link phase.
boot
This attribute directs the compiler to allocate a function in the boot segment of program
Flash.
For example, to declare a protected function:
void __attribute__((boot)) func();
An optional argument can be used to specify a protected access entry point within the
boot segment. The argument may be a literal integer in the range 0 to 31 (except 16),
or the word unused. Integer arguments correspond to 32 instruction slots in the seg-
ment access area, which occupies the lowest address range of each secure segment.
The value 16 is excluded because access entry 16 is reserved for the secure segment
interrupt vector. The value unused is used to specify a function for all of the unused
slots in the access area.
Access entry points facilitate the creation of application segments from different ven-
dors that are combined at run time. They can be specified for external functions as well
as locally defined functions. For example:
/* an external function that we wish to call */
extern void __attribute__((boot(3))) boot_service3();
/* local function callable from other segments */
void __attribute__((secure(4))) secure_service4()
{
boot_service3();
}
To specify a secure interrupt handler, use the boot attribute in combination with the
interrupt attribute:
void __attribute__((boot,interrupt)) boot_interrupts();
When an access entry point is specified for an external secure function, that function
need not be included in the project for a successful link. All references to that function
will be resolved to a fixed location in Flash, depending on the security model selected
at link time.
When an access entry point is specified for a locally defined function, the linker will
insert a branch instruction into the secure segment access area. The exception is for
access entry 16, which is represented as a vector (i.e, an instruction address) rather
than an instruction. The actual function definition will be located beyond the access
area; therefore the access area will contain a jump table through which control can be
transferred from another security segment to functions with defined entry points.
const
Many functions do not examine any values except their arguments, and have no effects
except the return value. Such a function can be subject to common subexpression
elimination and loop optimization just as an arithmetic operator would be. These
functions should be declared with the attribute const. For example:
int square (int) __attribute__ ((const int));
says that the hypothetical function square is safe to call fewer times than the program
says.
Note that a function that has pointer arguments and examines the data pointed to must
not be declared const. Likewise, a function that calls a non-const function usually
must not be const. It does not make sense for a const function to have a void return
type.
deprecated
See Section 2.3.1 “Specifying Attributes of Variables” for information on the
deprecated attribute.
far
The far attribute tells the compiler that the function should not be called using a more
efficient form of the call instruction.
near
The near attribute tells the compiler that the function can be called using a more
efficient form of the call instruction.
no_instrument_function
If the command line option -finstrument-function is given, profiling function calls
will be generated at entry and exit of most user-compiled functions. Functions with this
attribute will not be so instrumented.
noreturn
A few standard library functions, such as abort and exit, cannot return. The com-
piler knows this automatically. Some programs define their own functions that never
return. You can declare them noreturn to tell the compiler this fact. For example:
void fatal (int i) __attribute__ ((noreturn));
void
fatal (int i)
{
/* Print error message. */
exit (1);
}
The noreturn keyword tells the compiler to assume that fatal cannot return. It can
then optimize without regard to what would happen if fatal ever did return. This
makes slightly better code. Also, it helps avoid spurious warnings of uninitialized
variables.
It does not make sense for a noreturn function to have a return type other than void.
section ("section-name")
Normally, the compiler places the code it generates in the .text section. Sometimes,
however, you need additional sections, or you need certain functions to appear in
special sections. The section attribute specifies that a function lives in a particular
section. For example, consider the declaration:
extern void foobar (void) __attribute__ ((section (".libtext")));
This puts the function foobar in the .libtext section.
The section attribute conflicts with the address attribute. The section name will be
ignored with a warning.
secure
This attribute directs the compiler to allocate a function in the secure segment of
program Flash.
For example, to declare a protected function:
void __attribute__((secure)) func();
An optional argument can be used to specify a protected access entry point within the
secure segment. The argument may be a literal integer in the range 0 to 31 (except
16), or the word unused. Integer arguments correspond to 32 instruction slots in the
segment access area, which occupies the lowest address range of each secure seg-
ment. The value 16 is excluded because access entry 16 is reserved for the secure
segment interrupt vector. The value unused is used to specify a function for all of the
unused slots in the access area.
shadow
The shadow attribute causes the compiler to use the shadow registers rather than the
software stack for saving registers. This attribute is usually used in conjunction with the
interrupt attribute.
void __attribute__ ((interrupt, shadow)) _T1Interrupt (void);
unused
This attribute, attached to a function, means that the function is meant to be possibly
unused. The compiler will not produce an unused function warning for this function.
user_init
The user_init attribute may be applied to any non-interrupt function with void
parameter and return types. Applying this attribute will cause default C start-up mod-
ules to call this function before the user main is executed. There is no guarantee of
weak
See Section 2.3.1 “Specifying Attributes of Variables” for information on the weak
attribute.
Note: Function inlining will only take place when the function’s definition is visible
(not just the prototype). In order to have a function inlined into more than
one source file, the function definition may be placed into a header file that
is included by each of the source files.
To declare a function inline, use the inline keyword in its declaration, like this:
inline int
inc (int *a)
{
(*a)++;
}
(If you are using the -traditional option or the -ansi option, write __inline__
instead of inline.) You can also make all “simple enough” functions inline with the
command-line option -finline-functions. The compiler heuristically decides
which functions are simple enough to be worth integrating in this way, based on an
estimate of the function’s size.
Certain usages in a function definition can make it unsuitable for inline substitution.
Among these usages are: use of varargs, use of alloca, use of variable-sized data,
use of computed goto and use of nonlocal goto. Using the command-line option
-Winline will warn when a function marked inline could not be substituted, and will
give the reason for the failure.
In compiler syntax, the inline keyword does not affect the linkage of the function.
When a function is both inline and static, if all calls to the function are integrated
into the caller and the function’s address is never used, then the function’s own
assembler code is never referenced. In this case, the compiler does not actually output
assembler code for the function, unless you specify the command-line option
-fkeep-inline-functions. Some calls cannot be integrated for various reasons
(in particular, calls that precede the function’s definition cannot be integrated and
neither can recursive calls within the definition). If there is a nonintegrated call, then the
function is compiled to assembler code as usual. The function must also be compiled
Note: Using too many registers, in particular register W0, may impair the ability of
the 16-bit compiler to compile.
You can also specify the register in which an ordinary register variable should be
allocated.
• Global register variables reserve registers throughout the program. This may be
useful in programs such as programming language interpreters which have a
couple of global variables that are accessed very often.
• Local register variables in specific registers do not reserve the registers. The
compiler’s data flow analysis is capable of determining where the specified
registers contain live values, and where they are available for other uses. Stores
into local register variables may be deleted when they appear to be unused.
References to local register variables may be deleted, moved or simplified.
These local variables are sometimes convenient for use with the extended inline
assembly (see Chapter 9. “Mixing Assembly Language and C Modules”), if you
want to write one output of the assembler instruction directly into a particular register.
(This will work provided the register you specify fits the constraints specified for that
operand in the inline assembly statement).
r = __real__ z;
i = __imag__ z;
The operator ‘~’ performs complex conjugation when used on a value with a complex
type.
The compiler can allocate complex automatic variables in a noncontiguous fashion; it’s
even possible for the real part to be in a register while the imaginary part is on the stack
(or vice-versa). The debugging information format has no way to represent noncontig-
uous allocations like these, so the compiler describes noncontiguous complex
variables as two separate variables of noncomplex type. If the variable’s actual name
is foo, the two fictitious variables are named foo$real and foo$imag.
Note: This does not check whether the subscript is in bounds. (Array indexing in
C never does.)
Such an array of label values serves a purpose much like that of the switch
statement. The switch statement is cleaner and therefore preferable to an array.
Another use of label values is in an interpreter for threaded code. The labels within the
interpreter function can be stored in the threaded code for fast dispatching.
This mechanism can be misused to jump to code in a different function. The compiler
cannot prevent this from happening, so care must be taken to ensure that target
addresses are valid for the current function.
3.2 HIGHLIGHTS
Items discussed in this chapter are:
• Overview
• File Naming Conventions
• Options
• Environment Variables
• Predefined Macro Names
• Compiling a Single File on the Command Line
• Compiling Multiple Files on the Command Line
• Notable Symbols
3.3 OVERVIEW
The compilation driver program (pic30-gcc) compiles, assembles and links C and
assembly language modules and library archives. Most of the compiler command-line
options are common to all implementations of the GCC toolset. A few are specific to
the compiler.
The basic form of the compiler command line is:
pic30-gcc [options] files
Note: This executable name applies for all 16-bit compilers, i.e., MPLAB C Com-
piler for PIC24 MCUs and dsPIC® DSCs, MPLAB C Compiler for dsPIC®
DSCs, and MPLAB C Compiler for PIC24 MCUs.
Note: Command line options and file name extensions are case-sensitive.
For example, to compile, assemble and link the C source file hello.c, creating the
absolute executable hello.exe.
pic30-gcc -o hello.exe hello.c
3.5 OPTIONS
The compiler has many options for controlling compilation, all of which are
case-sensitive.
• Options Specific to dsPIC DSC Devices
• Options for Controlling the Kind of Output
• Options for Controlling the C Dialect
• Options for Controlling Warnings and Errors
• Options for Debugging
• Options for Controlling Optimization
• Options for Controlling the Preprocessor
• Options for Assembling
• Options for Linking
• Options for Directory Search
• Options for Code Generation Conventions
Note 1: The procedure abstractor behaves as the inverse of inlining functions. The pass is
designed to extract common code sequences from multiple sites throughout a
translation unit and place them into a common area of code. Although this option
generally does not improve the run-time performance of the generated code, it can
reduce the code size significantly. Programs compiled with -mpa can be harder to
debug; it is not recommended that this option be used while debugging using the
COFF object format.
The procedure abstractor is invoked as a separate phase of compilation, after the
production of an assembly file. This phase does not optimize across translation
units. When the procedure-optimizing phase is enabled, inline assembly code must
be limited to valid machine instructions. Invalid machine instructions or instruction
sequences, or assembler directives (sectioning directives, macros, include files,
etc.) must not be used, or the procedure abstraction phase will fail, inhibiting the
creation of an output file.
-x none
Turn off any specification of a language, so that subsequent files are
handled according to their file name suffixes. This is the default
behavior but is needed if another -x option has been used.
For example:
pic30-gcc -x assembler foo.asm bar.asm -x none
main.c mabonga.s
Without the -x none, the compiler will assume all the input files are for
the assembler.
--help Print a description of the command line options.
-Os Optimize for size. -Os enables all -O2 optimizations that do
not typically increase code size. It also performs further
optimizations designed to reduce code size.
The following options control specific optimizations. The -O2 option turns on all of
these optimizations except -funroll-loops, -funroll-all-loops and
-fstrict-aliasing.
You can use the following flags in the rare cases when “fine-tuning” of optimizations to
be performed is desired.
TABLE 3-9: SPECIFIC OPTIMIZATION OPTIONS
Option Definition
-falign-functions Align the start of functions to the next power-of-two greater
-falign-functions=n than n, skipping up to n bytes. For instance,
-falign-functions=32 aligns functions to the next
32-byte boundary, but -falign-functions=24 would align
to the next 32-byte boundary only if this can be done by
skipping 23 bytes or less.
-fno-align-functions and -falign-functions=1 are
equivalent and mean that functions will not be aligned.
The assembler only supports this flag when n is a power of
two; so n is rounded up. If n is not specified, use a
machine-dependent default.
-falign-labels Align all branch targets to a power-of-two boundary, skipping
-falign-labels=n up to n bytes like -falign-functions. This option can
easily make code slower, because it must insert dummy
operations for when the branch target is reached in the usual
flow of the code.
If -falign-loops or -falign-jumps are applicable and
are greater than this value, then their values are used instead.
If n is not specified, use a machine-dependent default which is
very likely to be 1, meaning no alignment.
-falign-loops Align loops to a power-of-two boundary, skipping up to n bytes
-falign-loops=n like -falign-functions. The hope is that the loop will be
executed many times, which will make up for any execution of
the dummy operations.
If n is not specified, use a machine-dependent default.
-fcaller-saves Enable values to be allocated in registers that will be
clobbered by function calls, by emitting extra instructions to
save and restore the registers around such calls. Such
allocation is done only when it seems to result in better code
than would otherwise be produced.
int f() {
union a_union t;
t.d = 3.0;
return t.i;
}
The practice of reading from a different union member than
the one most recently written to (called “type-punning”) is
common. Even with -fstrict-aliasing, type-punning is
allowed, provided the memory is accessed through the union
type. So, the code above will work as expected. However, this
code might not:
int f() {
a_union t;
int* ip;
t.d = 3.0;
ip = &t.i;
return *ip;
}
_prog_addressT big_addr;
_init_prog_address(big_addr, _PROGRAM_END)
4.2 HIGHLIGHTS
Items discussed in this chapter are:
• Address Spaces
• Startup and Initialization
• Memory Spaces
• Memory Models
• Locating Code and Data
• Software Stack
• The C Stack Usage
• The C Heap Usage
• Function Call Conventions
• Register Conventions
• Bit Reversed and Modulo Addressing
• Program Space Visibility (PSV) Usage
4. If the application has defined user_init functions, these are invoked. The
order of execution depends on link order.
5. The function main is called with no parameters.
6. If main returns, the processor will reset.
The alternate startup module (crt1.o) is linked when the -Wl, --no-data-init
option is specified. It performs the same operations, except for step (3), which is
omitted. The alternate startup module is smaller than the primary module, and can be
selected to conserve program memory if data initialization is not required.
Source code (in dsPIC DSC assembly language) for both modules is provided in the
c:\Program Files\Microchip\MPLAB C30\src directory. The startup modules
may be modified if necessary. For example, if an application requires main to be called
with parameters, a conditional assembly directive may be changed to provide this
support.
data
General data space. Variables in general data space can be accessed using ordinary
C statements. This is the default allocation.
prog
General program space, which is normally reserved for executable code. Variables in
program space can not be accessed using ordinary C statements. They must be
explicitly accessed by the programmer, usually using table-access inline assembly
instructions, or using the program space visibility window.
auto_psv
A compiler-managed area in program space, designated for program space visibility
window access. Variables in this space can be read (but not written) using ordinary C
statements and are subject to a maximum of 32K total space allocated.
psv
Program space, designated for program space visibility window access. Variables in
PSV space are not managed by the compiler and can not be accessed using ordinary
C statements. They must be explicitly accessed by the programmer, usually using
table-access inline assembly instructions, or using the program space visibility window.
Variables in PSV space can be accessed using a single setting of the PSVPAG register.
The C run-time startup modules (crt0.o and crt1.o in libpic30.a) initialize the
Stack Pointer W15 to point to the bottom of the stack and initialize the Stack Pointer
Limit register to point to the top of the stack. The stack grows up and if it should grow
beyond the value in the Stack Pointer Limit register, then a stack error trap will be taken.
The user may initialize the Stack Pointer Limit register to further restrict stack growth.
The following diagrams illustrate the steps involved in calling a function. Executing a
CALL or RCALL instruction pushes the return address onto the software stack. See
Figure 4-2.
SP (W15)
Parameter n
FP (W14)
Caller’s Frame
The called function (callee) can now allocate space for its local context (Figure 4-3).
SP (W15)
Previous FP
Parameter n-1
Parameter n
Caller’s Frame
SP (W15)
Callee-Saved
Registers [W14+n] accesses
local context
Local Variables FP (W14)
and Temporaries [W14-n] accesses
stack-based
Previous FP function parameters
Stack grows
toward Return addr [23:16]
greater
addresses Return addr [15:0]
Parameter 1
Parameter n-1
Parameter n
Caller’s Frame
void
params1(int i, bar b) {
/*
** W0 i
** W1 b.i
** W5:W2 b.d
*/
}
Parameters corresponding to the ellipses (...) of a variable-length argument list are not
allocated to registers. Any parameter not allocated to registers is pushed onto the
stack, in right-to-left order.
In the next example, the structure parameter cannot be placed in registers because it
is too large. However, this does not prevent the next parameter from using a register
spot.
void
params2(int i, bar b, int j) {
/*
** W0 i
** stack b
** W1 j
*/
}
Accessing arguments that have been placed onto the stack depends upon whether or
not a Frame Pointer has been created. Generally the compiler will produce a Frame
Pointer (unless otherwise told not to do so), and stack-based parameters will be
accessed via the Frame Pointer register (W14). The above example, b will be
accessed from W14-22. The Frame Pointer offset of negative 22 has been calculated
(refer to Figure 4-4) by removing 2 bytes for the previous FP, 4 bytes for the return
address, followed by 16 bytes for b.
When no Frame Pointer is used, the assembly programmer must know how much stack
space has been used since entry to the procedure. If no further stack space is used,
the calculation is similar to the above. b would be accessed via W15-20; 4 bytes for the
return address and 16 bytes to access the start of b.
5.2 HIGHLIGHTS
Items discussed in this chapter are:
• Data Representation
• Integer
• Floating Point
• Pointers
w4 w5
0x5678 0x1234
5.4 INTEGER
Table 5-1 shows integer data types are supported in the compiler.
TABLE 5-1: INTEGER DATA TYPES
Type Bits Min Max
char, signed char 8 -128 127
unsigned char 8 0 255
short, signed short 16 -32768 32767
unsigned short 16 0 65535
int, signed int 16 -32768 32767
unsigned int 16 0 65535
long, signed long 32 -231 231 - 1
unsigned long 32 0 232 - 1
long long**, signed long long** 64 -263 263 - 1
unsigned long long** 64 0 264 - 1
** ANSI-89 extension
5.6 POINTERS
All standard pointers are 16-bits wide. This is sufficient for full data space access
(64 KB) and the small code model (32 Kwords of code.) In the large code model
(>32 Kwords of code), pointers may resolve to “handles”; that is, the pointer is the
address of a GOTO instruction which is located in the first 32 Kwords of program space.
A set of special purpose, 32-bit data pointers are also available. See
Chapter 6. “Additional C Pointer Types” for more information.
read_external
void __read_external(unsigned int address,
unsigned int memory_space,
void *buffer,
unsigned int len)
This function is a generic Read function and will be called if one of the next functions
are required but not defined. This function should perform the steps necessary to fill
len bytes of memory in the buffer from the external memory named memory_space
starting at address address.
read_external8
unsigned char __read_external8(unsigned int address,
unsigned int memory_space)
Read 8 bits from external memory space memory_space starting from address
address. The compiler would like to call this function if trying to access an 8-bit sized
object.
read_external16
unsigned int __read_external16(unsigned int address,
unsigned int memory_space)
Read 16 bits from external memory space memory_space starting from address
address. The compiler would like to call this function if trying to access an 16-bit sized
object.
read_external32
unsigned long __read_external32(unsigned int address,
unsigned int memory_space)
Read 32 bits from external memory space memory_space starting from address
address. The compiler would like to call this function if trying to access a 32-bit sized
object, such as a long or float type.
read_external64
unsigned long long __read_external64(unsigned int address,
unsigned int memory_space)
Read 64 bits from external memory space memory_space starting from address
address. The compiler would like to call this function if trying to access a 64-bit sized
object, such as a long long or long double type.
write_external
void __write_external(unsigned int address,
unsigned int memory_space,
void *buffer,
unsigned int len)
This function is a generic Write function and will be called if one of the next functions
are required but not defined. This function should perform the steps necessary to write
len bytes of memory from the buffer to the external memory named memory_space
starting at address address.
write_external8
void __write_external8(unsigned int address,
unsigned int memory_space,
unsigned char data)
Write 8 bits of data to external memory space memory_space starting from address
address. The compiler would like to call this function if trying to write an 8-bit sized
object.
write_external16
void __write_external16(unsigned int address,
unsigned int memory_space,
unsigned int data)
Write 16 bits of data to external memory space memory_space starting from address
address. The compiler would like to call this function if trying to write an 16-bit sized
object.
write_external32
void __write_external32(unsigned int address,
unsigned int memory_space,
unsigned long data)
Write 32 bits of data to external memory space memory_space starting from address
address. The compiler would like to call this function if trying to write a 32-bit sized
object, such as a long or float type.
write_external64
void __write_external64(unsigned int address,
unsigned int memory_space,
unsigned long long data)
Write 64 bits of data to external memory space memory_space starting from address
address. The compiler would like to call this function if trying to write a 64-bit sized
object, such as a long long or long double type.
7.2 HIGHLIGHTS
Items discussed in this chapter are:
• Processor Header Files
• Register Definition Files
• Using SFRs
• Using Macros
• Accessing EEDATA from C Code - dsPIC30F dSCs only
Note: The symbols CORCON and CORCONbits refer to the same register and
will resolve to the same address at link time.
#include <p30f6014.h>
struct clockType
{
unsigned int timer; /* countdown timer, milliseconds */
unsigned int ticks; /* absolute time, milliseconds */
unsigned int seconds; /* absolute time, seconds */
} volatile RTclock;
void reset_clock(void)
{
RTclock.timer = 0; /* clear software registers */
RTclock.ticks = 0;
RTclock.seconds = 0;
Note: ISRs will be installed into the interrupt vector tables automatically if the
reserved names listed in Section 8.4 “Writing the Interrupt Vector” are
used.
/* ... */
}
These steps need only be done once. Unless PSVPAG is changed, variables in EE
data space may be read by referring to them as normal C variables, as shown in the
example.
Note: This access model is not compatible with the compiler-managed PSV
(-mconst-in-code) model. You should be careful to prevent conflict.
int main(void) {
int value;
TBLPAG = __builtin_tblpage(&user_data);
eedata_read(user_data,2*sizeof(user_data[0]), value);
if (value) ; /* do something */
Chapter 8. Interrupts
8.1 INTRODUCTION
Interrupt processing is an important aspect of most microcontroller applications.
Interrupts may be used to synchronize software operations with events that occur in
real time. When interrupts occur, the normal flow of software execution is suspended
and special functions are invoked to process the event. At the completion of interrupt
processing, previous context information is restored and normal execution resumes.
The 16-bit devices support multiple interrupts from both internal and external sources.
In addition, the devices allow high-priority interrupts to override any low priority inter-
rupts that may be in progress.
The compiler provides full support for interrupt processing in C or inline assembly code.
This chapter presents an overview of interrupt processing.
8.2 HIGHLIGHTS
Items discussed in this chapter are:
• Writing an Interrupt Service Routine – You can designate one or more C
functions as Interrupt Service Routines (ISR’s) to be invoked by the occurrence of
an interrupt. For best performance in general, place lengthy calculations or opera-
tions that require library calls in the main application. This strategy optimizes
performance and minimizes the possibility of losing information when interrupt
events occur rapidly.
• Writing the Interrupt Vector – The 16-bit devices use interrupt vectors to transfer
application control when an interrupt occurs. An interrupt vector is a dedicated
location in program memory that specifies the address of an ISR. Applications
must contain valid function addresses in these locations to use interrupts.
• Interrupt Service Routine Context Saving – To handle returning from an
interrupt to code in the same conditional state as before the interrupt, context
information from specific registers must be saved.
• Latency – The time between when an interrupt is called and when the first ISR
instruction is executed is the latency of the interrupt.
• Nesting Interrupts – The compiler supports nested interrupts.
• Enabling/Disabling Interrupts – Enabling and disabling interrupt sources occurs
at two levels: globally and individually.
• Sharing Memory Between Interrupt Service Routines and Mainline Code –
How to mitigate potential hazards when this technique is used.
• PSV Usage with Interrupt Service Routines – Using ISRs with managed psv
pointers and CodeGuard Security psv constant sections.
Note: A device reset is not handled through the interrupt vector table. Instead,
upon device reset, the program counter is cleared. This causes the
processor to begin execution at address zero. By convention, the linker
script constructs a GOTO instruction at that location which transfers control
to the C run-time startup module.
8.6 LATENCY
There are two elements that affect the number of cycles between the time the interrupt
source occurs and the execution of the first instruction of your ISR code. These are:
• Processor Servicing of Interrupt – The amount of time it takes the processor to
recognize the interrupt and branch to the first address of the interrupt vector. To
determine this value refer to the processor data sheet for the specific processor
and interrupt source being used.
• ISR Code – The compiler saves the registers that it uses in the ISR. This includes
the working registers and the RCOUNT special function register. Moreover, if the
ISR calls an ordinary function, then the compiler will save all the working registers
and RCOUNT, even if they are not all used explicitly in the ISR itself. This must be
done, because the compiler cannot know, in general, which resources are used by
the called function.
Note: Traps, such as the address error trap, cannot be disabled. Only IRQs can
be disabled.
The DISI instruction can be used in a C program through inline assembly. For
example, the inline assembly statement:
__asm__ volatile ("disi #16");
will emit the specified DISI instruction at the point it appears in the source program. A
disadvantage of using DISI in this way is that the C programmer cannot always be
sure how the C compiler will translate C source to machine instructions, so it may be
difficult to determine the cycle count for the DISI instruction. It is possible to get around
this difficulty by bracketing the code that is to be protected from interrupts by DISI
instructions, the first of which sets the cycle count to the maximum value, and the
second of which sets the cycle count to zero. For example,
__asm__ volatile("disi #0x3FFF"); /* disable interrupts */
/* ... protected C code ... */
__asm__ volatile("disi #0x0000"); /* enable interrupts */
An alternative approach is to write directly to the DISICNT register to enable interrupts.
The DISICNT register may be modified only after a DISI instruction has been issued
and if the contents of the DISICNT register are not zero.
__asm__ volatile("disi #0x3FFF"); /* disable interrupts */
/* ... protected C code ... */
DISICNT = 0x0000; /* enable interrupts */
For some applications, it may be necessary to disable level 7 interrupts as well. These
can only be disabled through the modification of the COROCON IPL field. The provided
support files contain some useful preprocessor macro functions to help you safely
modify the IPL value. These macros are:
SET_CPU_IPL(ipl)
SET_AND_SAVE_CPU_IPL(save_to, ipl)
RESTORE_CPU_IPL(saved_to)
For example, you may wish to protect a section of code from interrupt. The following
code will adjust the current IPL setting and restore the IPL to its previous value.
void foo(void) {
int current_cpu_ipl;
int main(void) {
/* More User Code */
LATGbits.LATG10 ^= 1; /* Potential HAZARD -
First reads LATG into a W reg,
implements XOR operation,
then writes result to LATG */
IPC0bits.T1IP = 5; /* HAZARD -
Assigning a multiple bitfield
can generate a multiple
instruction sequence */
}
A statement can be protected from interrupt using the INTERRUPT_PROTECT macro
provided above. For this example:
INTERRUPT_PROTECT(LATGbits.LATG15 ^= 1); /* Not interruptible by
level 1-7 interrupt
requests and safe
at any optimization
level */
9.2 HIGHLIGHTS
Items discussed in this chapter are:
• Mixing Assembly Language and C Variables and Functions – Separate
assembly language modules may be assembled, then linked with compiled C
modules.
• Using Inline Assembly Language – Assembly language instructions may be
embedded directly into the C code. The inline assembler supports both simple
(non-parameterized) assembly language statement, as well as extended
(parameterized) statements, where C variables can be accessed as operands of
an assembler instruction.
.global _begin
_main:
call _foo
return
.bss
.global _asmVariable
.align 2
_asmVariable: .space 2
.end
In the C file, ex1.c, external references to symbols declared in an assembly file are
declared using the standard extern keyword; note that asmFunction, or
_asmFunction in the assembly source, is a void function and is declared
accordingly.
In the assembly file, ex1.s, the symbols _asmFunction, _main and _asmVariable
are made globally visible through the use of the .global assembler directive and can
be accessed by any other source file. The symbol _main is only referenced and not
declared; therefore, the assembler takes this to be an external reference.
The following compiler example shows how to call an assembly function with two
parameters. The C function main in call1.c calls the asmFunction in call2.s
with two parameters.
Note: Only a single string can be passed to the simple form of inline
assembly.
In an extended assembler instruction using asm, the operands of the instruction are
specified using C expressions. The extended syntax is:
asm("template" [ : [ "constraint"(output-operand) [ , ... ] ]
[ : [ "constraint"(input-operand) [ , ... ] ]
[ "clobber" [ , ... ] ]
]
]);
You must specify an assembler instruction template, plus an operand constraint
string for each operand. The template specifies the instruction mnemonic, and
optionally placeholders for the operands. The constraint strings specify operand
constraints, for example, that an operand must be in a register (the usual case), or that
an operand must be an immediate value.
Constraint letters and modifiers supported by the compiler are listed in Table 9-1 and
Table 9-2 respectively.
This example demonstrates how to use the swap instruction (which the compiler does
not generally use):
asm ("swap %0" : "+r"(var));
Here var is the C expression for the operand, which is both an input and an output
operand. The operand is constrained to be of type r, which denotes a register operand.
The + in +r indicates that the operand is both an input and output operand.
Each operand is described by an operand-constraint string followed by the C expres-
sion in parentheses. A colon separates the assembler template from the first output
operand, and another separates the last output operand from the first input, if any.
Commas separate output operands and separate inputs.
return(c);
}
The intention is to compute the value (a + b) << a. However, as written, the value
computed may or may not be this value. The correct coding informs the compiler that
the operand c is modified before the asm instruction is finished using the input
operands, as follows:
int
exprgood(int a, int b)
{
int c;
return(c);
}
asm("error: ");
return 1;
This is unacceptable as the compiler will assume that the next statement, return 0,
is executed when it may not be. In this case, the asm("error: ") and following state-
ments will be deleted because they are unreachable. See further information regarding
labels in asm statements.
in1 = some_input1;
in2 = some_input2;
__asm__ volatile ("funky_instruction %2,%3,%0; = %1" :
/* outputs */ "=r"(out1), "=r"(out2) :
/* inputs */ "r"(in1), "r"(in2));
/* use out1 and out2 in normal C */
}
In this example, funky_instruction has one explicit output, out1, and one implicit
output, out2. Both have been placed in the asm template so that the compiler can
track the register usage properly (though the implicit output is in a comment statement).
The input shown is normal. Otherwise, the extended register declarator syntax is used
to nominate particular hard registers which satisfy the constraints of our fictitious
funky_instruction.
A.2 HIGHLIGHTS
Items discussed in this chapter are:
• Translation
• Environment
• Identifiers
• Characters
• Integers
• Floating Point
• Arrays and Pointers
• Registers
• Structures, Unions, Enumerations and Bit fields
• Qualifiers
• Declarators
• Statements
• Preprocessing Directives
• Library Functions
• Signals
• Streams and Files
• tmpfile
• errno
• Memory
• abort
• exit
• getenv
• system
• strerror
A.3 TRANSLATION
Implementation-Defined Behavior for Translation is covered in section G.3.1 of the
ANSI C Standard.
Is each non-empty sequence of white-space characters, other than new line, retained
or is it replaced by one space character? (ISO 5.1.1.2)
It is replaced by one space character.
How is a diagnostic message identified? (ISO 5.1.1.3)
Diagnostic messages are identified by prefixing them with the source file name and line
number corresponding to the message, separated by colon characters (‘:’).
Are there different classes of message? (ISO 5.1.1.3)
Yes.
If yes, what are they? (ISO 5.1.1.3)
Errors, which inhibit production of an output file, and warnings, which do not inhibit
production of an output file.
What is the translator return status code for each class of message? (ISO 5.1.1.3)
The return status code for errors is 1; for warnings it is 0.
Can a level of diagnostic be controlled? (ISO 5.1.1.3)
Yes.
If yes, what form does the control take? (ISO 5.1.1.3)
Compiler command line options may be used to request or inhibit the generation of
warning messages.
A.4 ENVIRONMENT
Implementation-Defined Behavior for Environment is covered in section G.3.2 of the
ANSI C Standard.
What library facilities are available to a freestanding program? (ISO 5.1.2.1)
All of the facilities of the standard C library are available, provided that a small set of
functions is customized for the environment, as described in the “Run Time Libraries”
section.
Describe program termination in a freestanding environment. (ISO 5.1.2.1)
If the function main returns or the function exit is called, a HALT instruction is executed
in an infinite loop. This behavior is customizable.
Describe the arguments (parameters) passed to the function main? (ISO 5.1.2.2.1)
No parameters are passed to main.
Which of the following is a valid interactive device: (ISO 5.1.2.3)
Asynchronous terminalNo
Paired display and keyboardNo
Inter program connectionNo
Other, please describe?None
A.5 IDENTIFIERS
Implementation-Defined Behavior for Identifiers is covered in section G.3.3 of the ANSI
C Standard.
How many characters beyond thirty-one (31) are significant in an identifier without
external linkage? (ISO 6.1.2)
All characters are significant.
How many characters beyond six (6) are significant in an identifier with external
linkage? (ISO 6.1.2)
All characters are significant.
Is case significant in an identifier with external linkage? (ISO 6.1.2)
Yes.
A.6 CHARACTERS
Implementation-Defined Behavior for Characters is covered in section G.3.4 of the
ANSI C Standard.
Detail any source and execution characters which are not explicitly specified by the
Standard? (ISO 5.2.1)
None.
List escape sequence value produced for listed sequences. (ISO 5.2.2)
A.7 INTEGERS
Implementation-Defined Behavior for Integers is covered in section G.3.5 of the ANSI
C Standard.
The following table describes the amount of storage and range of various types of
integers: (ISO 6.1.2.5)
What is the result of converting an integer to a shorter signed integer, or the result of
converting an unsigned integer to a signed integer of equal length, if the value cannot
be represented? (ISO 6.2.1.2)
There is a loss of significance. No error is signaled.
What are the results of bitwise operations on signed integers? (ISO 6.3)
Shift operators retain the sign. Other operators act as if the operand(s) are unsigned
integers.
What is the sign of the remainder on integer division? (ISO 6.3.5)
+
What is the result of a right shift of a negative-valued signed integral type? (ISO 6.3.7)
The sign is retained.
A.10 REGISTERS
Implementation-Defined Behavior for Registers is covered in section G.3.8 of the ANSI
C Standard.
To what extent does the storage class specifier register actually effect the storage
of objects in registers? (ISO 6.5.1)
If optimization is disabled, an attempt will be made to honor the register storage
class; otherwise, it is ignored.
A.12 QUALIFIERS
Implementation-Defined Behavior for Qualifiers is covered in section G.3.10 of the
ANSI C Standard.
Describe what action constitutes an access to an object that has volatile-qualified type?
(ISO 6.5.3)
If an object is named in an expression, it has been accessed.
A.13 DECLARATORS
Implementation-Defined Behavior for Declarators is covered in section G.3.11 of the
ANSI C Standard.
What is the maximum number of declarators that may modify an arithmetic, structure,
or union type? (ISO 6.5.4)
No limit.
A.14 STATEMENTS
Implementation-Defined Behavior for Statements is covered in section G.3.12 of the
ANSI C Standard.
What is the maximum number of case values in a switch statement? (ISO 6.6.4.2)
No limit.
What are the definitions for __ DATE __ and __ TIME __ respectively, when the date
and time of translation are not available? (ISO 6.8.8)
Not applicable. The compiler is not supported in environments where these functions
are not available.
What values are returned by the mathematics functions after a domain errors?
(ISO 7.5.1)
NaN.
Do the mathematics functions set the integer expression errno to the value of the
macro ERANGE on underflow range errors? (ISO 7.5.1)
Yes.
Do you get a domain error or is zero returned when the fmod function has a second
argument of zero? (ISO 7.5.6.4)
Domain error.
A.17 SIGNALS
What is the set of signals for the signal function? (ISO 7.7.1.1)
Describe the parameters and the usage of each signal recognized by the signal
function. (ISO 7.7.1.1)
Application defined.
Describe the default handling and the handling at program startup for each signal
recognized by the signal function? (ISO 7.7.1.1)
None.
If the equivalent of signal (sig,SIG_DFL) is not executed prior to the call of a signal han-
dler, what blocking of the signal is performed? (ISO 7.7.1.1)
None.
Is the default handling reset if a SIGILL signal is received by a handler specified to the
signal function? (ISO 7.7.1.1)
No.
A.19 TMPFILE
Is an open temporary file removed if the program terminates abnormally? (ISO 7.9.4.3)
Yes.
A.20 ERRNO
What value is the macro errno set to by the fgetpos or ftell function on failure?
(ISO 7.9.9.1, (ISO 7.9.9.4)
Application defined.
What is the format of the messages generated by the perror function? (ISO 7.9.10.4)
The argument to perror, followed by a colon, followed by a text description of the
value of errno.
A.21 MEMORY
What is the behavior of the calloc, malloc or realloc function if the size requested
is zero? (ISO 7.10.3)
A block of zero length is allocated.
A.22 ABORT
What happens to open and temporary files when the abort function is called?
(ISO 7.10.4.1)
Nothing.
A.23 EXIT
What is the status returned by the exit function if the value of the argument is other than
zero, EXIT_SUCCESS, or EXIT_FAILURE? (ISO 7.10.4.3)
The value of the argument.
A.24 GETENV
What limitations are there on environment names? (ISO 7.10.4.4)
Application defined.
Describe the method used to alter the environment list obtained by a call to the getenv
function. (ISO 7.10.4.4)
Application defined.
A.25 SYSTEM
Describe the format of the string that is passed to the system function. (ISO 7.10.4.5)
Application defined.
What mode of execution is performed by the system function? (ISO 7.10.4.5)
Application defined.
A.26 STRERROR
Describe the format of the error message output by the strerror function.
(ISO 7.11.6.2)
A plain character string.
List the contents of the error message strings returned by a call to the strerror
function. (ISO 7.11.6.2)
__builtin_addab
Description: Add accumulators A and B with the result written back to the specified
accumulator. For example:
register int result asm("A");
result = __builtin_addab();
will generate:
add A
Prototype: int __builtin_addab(void);
Argument: None
Return Value: Returns the addition result to an accumulator.
Assembler Opera- addad
tor / Machine
Instruction:
Error Messages An error message will be displayed if the result is not an accumulator
register.
__builtin_add
Description: Add value to the accumulator specified by result with a shift
specified by literal shift. For example:
register int result asm("A");
int value;
result = __builtin_add(value,0);
If value is held in w0, the following will be generated:
add w0, #0, A
Prototype: int __builtin_add(int value, const int shift);
Argument: value Integer number to add to accumulator value.
shift Amount to shift resultant accumulator value.
Return Value: Returns the shifted addition result to an accumulator.
Assembler Opera- add
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_btg
Description: This function will generate a btg machine instruction.
Some examples include:
struct foo {
int bit1:1;
} barbits;
int bar;
void some_bittoggles() {
register int j asm("w9");
int k;
k = i;
__builtin_btg(&i,1);
__builtin_btg(&j,3);
__builtin_btg(&k,4);
__builtin_btg(&l,11);
return j+k;
}
__builtin_clr
Description: Clear the specified accumulator. For example:
register int result asm("A");
result = __builtin_clr();
will generate:
clr A
Prototype: int __builtin_clr(void);
Argument: None
Return Value: Returns the cleared value result to an accumulator.
__builtin_clr
Assembler Opera- clr
tor / Machine
Instruction:
Error Messages An error message will be displayed if the result is not an accumulator
register.
__builtin_clr_prefetch
Description: Clear an accumulator and prefetch data ready for a future MAC
operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
If AWB is non null, the other accumulator will be written back into the
referenced variable.
For example:
register int result asm("A");
int x_memory_buffer[256]
__attribute__((space(xmemory)));
int y_memory_buffer[256]
__attribute__((space(ymemory)));
int *xmemory;
int *ymemory;
int awb;
int xVal, yVal;
xmemory = x_memory_buffer;
ymemory = y_memory_buffer;
result = __builtin_clr(&xmemory, &xVal, 2,
&ymemory, &yVal, 2, &awb);
might generate:
clr A, [w8]+=2, w4, [w10]+=2, w5, w13
The compiler may need to spill w13 to ensure that it is available for the
write-back. It may be recommended to users that the register be
claimed for this purpose.
After this instruction:
• result will be cleared
• xVal will contain x_memory_buffer[0]
• yVal will contain y_memory_buffer[0]
• xmemory and ymemory will be incremented by 2, ready for the
next mac operation
Prototype: int __builtin_clr_prefetch(
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB);
__builtin_clr_prefetch
Argument: xptr Integer pointer to x prefetch.
xval Integer value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to y prefetch.
yval Integer value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Accumulator selection.
Return Value: Returns the cleared value result to an accumulator.
Assembler Opera- clr
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_divf
Description: Computes the quotient num / den. A math error exception occurs if den
is zero. Function arguments are unsigned, as is the function result.
Prototype: unsigned int __builtin_divf(unsigned int num,
unsigned int den);
Argument: num numerator
den denominator
Return Value: Returns the unsigned integer value of the quotient num / den.
Assembler Opera- div.f
tor / Machine
Instruction:
__builtin_divmodsd
Description: Issues the 16-bit architecture’s native signed divide support with the
same restrictions given in the “dsPIC30F/33F Programmer’s Reference
Manual” (DS70157). Notably, if the quotient does not fit into a 16-bit
result, the results (including remainder) are unexpected. This form of
the builtin function will capture both the quotient and remainder.
Prototype: signed int __builtin_divmodsd(
signed long dividend, signed int divisor,
signed int *remainder);
Argument: dividendnumber to be divided
divisornumber to divide by
remainderpointer to remainder
Return Value: Quotient and remainder.
Assembler Opera- divmodsd
tor / Machine
Instruction:
Error Messages None.
__builtin_divmodud
Description: Issues the 16-bit architecture’s native unsigned divide support with the
same restrictions given in the “dsPIC30F/33F Programmer’s Refer-
ence Manual” (DS70157). Notably, if the quotient does not fit into a
16-bit result, the results (including remainder) are unexpected. This
form of the builtin function will capture both the quotient and remainder.
Prototype: unsigned int __builtin_divmodud(
unsigned long dividend, unsigned int divisor,
unsigned int *remainder);
Argument: dividendnumber to be divided
divisornumber to divide by
remainderpointer to remainder
Return Value: Quotient and remainder.
Assembler Opera- divmodud
tor / Machine
Instruction:
Error Messages None.
__builtin_divsd
Description: Computes the quotient num / den. A math error exception occurs if den
is zero. Function arguments are signed, as is the function result. The
command-line option -Wconversions can be used to detect unex-
pected sign conversions.
Prototype: int __builtin_divsd(const long num, const int den);
Argument: num numerator
den denominator
Return Value: Returns the signed integer value of the quotient num / den.
Assembler Opera- div.sd
tor / Machine
Instruction:
__builtin_divud
Description: Computes the quotient num / den. A math error exception occurs if den
is zero. Function arguments are unsigned, as is the function result. The
command-line option -Wconversions can be used to detect unex-
pected sign conversions.
Prototype: unsigned int __builtin_divud(const unsigned
long num, const unsigned int den);
Argument: num numerator
den denominator
Return Value: Returns the unsigned integer value of the quotient num / den.
Assembler Opera- div.ud
tor / Machine
Instruction:
__builtin_dmaoffset
Description: Obtains the offset of a symbol within DMA memory.
For example:
unsigned int result;
char buffer[256] __attribute__((space(dma)));
result = __builtin_dmaoffset(&buffer);
Might generate:
mov #dmaoffset(buffer), w0
Prototype: unsigned int __builtin_dmaoffset(const void *p);
Argument: *p pointer to DMA address value
Return Value: Returns the offset to a variable located in DMA memory.
Assembler Opera- dmaoffset
tor / Machine
Instruction:
Error Messages An error message will be displayed if the parameter is not the address
of a global symbol.
__builtin_ed
Description: Squares sqr, returning it as the result. Also prefetchs data for future
square operation by computing **xptr - **yptr and storing the
result in *distance.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
For example:
register int result asm("A");
int *xmemory, *ymemory;
int distance;
result = __builtin_ed(distance,
&xmemory, 2,
&ymemory, 2,
&distance);
might generate:
ed w4*w4, A, [w8]+=2, [W10]+=2, w4
Prototype: int __builtin_ed(int sqr, int **xptr, int xincr,
int **yptr, int yincr, int *distance);
Argument: sqr Integer squared value.
xptr Integer pointer to pointer to x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yincr Integer increment value of y prefetch.
distance Integer pointer to distance.
Return Value: Returns the squared result to an accumulator.
Assembler Opera- ed
tor / Machine
Instruction:
__builtin_ed
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xptr is null
• yptr is null
• distance is null
__builtin_edac
Description: Squares sqr and sums with the nominated accumulator register,
returning it as the result. Also prefetchs data for future square operation
by computing **xptr - **yptr and storing the result in *distance.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
For example:
register int result asm("A");
int *xmemory, *ymemory;
int distance;
result = __builtin_ed(distance,
&xmemory, 2,
&ymemory, 2,
&distance);
might generate:
ed w4*w4, A, [w8]+=2, [W10]+=2, w4
Prototype: int __builtin_edac(int sqr, int **xptr, int xincr,
int **yptr, int yincr, int *distance);
Argument: sqr Integer squared value.
xptr Integer pointer to pointer to x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yincr Integer increment value of y prefetch.
distance Integer pointer to distance.
Return Value: Returns the squared result to specified accumulator.
Assembler Opera- edac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xptr is null
• yptr is null
• distance is null
__builtin_fbcl
Description: Finds the first bit change from left in value. This is useful for dynamic
scaling of fixed-point data. For example:
int result, value;
result = __builtin_fbcl(value);
might generate:
fbcl w4, w5
Prototype: int __builtin_fbcl(int value);
__builtin_fbcl
Argument: valueInteger number of first bit change.
Return Value: Returns the shifted addition result to an accumulator.
Assembler Opera- fbcl
tor / Machine
Instruction:
Error Messages An error message will be displayed if the result is not an accumulator
register.
__builtin_lac
Description: Shifts value by shift (a literal between -8 and 7) and returns the value
to be stored into the accumulator register. For example:
register int result asm("A");
int value;
result = __builtin_lac(value,3);
Might generate:
lac w4, #3, A
Prototype: int __builtin_lac(int value, int shift);
Argument: valueInteger number to be shifted.
shiftLiteral amount to shift.
Return Value: Returns the shifted addition result to an accumulator.
Assembler Opera- lac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_mac
Description: Computes a x b and sums with accumulator; also prefetchs data ready
for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
If AWB is non null, the other accumulator will be written back into the
referenced variable.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
might generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype: int __builtin_mac(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB);
Argument: a Integer multiplicand.
b Integer multiplier.
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Integer pointer to accumulator selection.
Return Value: Returns the cleared value result to an accumulator.
Assembler Opera- mac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_modsd
Description: Issues the 16-bit architecture’s native signed divide support with the
same restrictions given in the “dsPIC30F/33F Programmer’s Refer-
ence Manual” (DS70157). Notably, if the quotient does not fit into a
16-bit result, the results (including remainder) are unexpected. This
form of the builtin function will capture only the remainder.
Prototype: signed int __builtin_modsd(signed long dividend,
signed int divisor);
__builtin_modsd
Argument: dividend number to be divided
divisor number to divide by
Return Value: Remainder.
Assembler Opera- modsd
tor / Machine
Instruction:
Error Messages None.
__builtin_modud
Description: Issues the 16-bit architecture’s native unsigned divide support with the
same restrictions given in the “dsPIC30F/33F Programmer’s Refer-
ence Manual” (DS70157). Notably, if the quotient does not fit into a
16-bit result, the results (including remainder) are unexpected. This
form of the builtin function will capture only the remainder.
Prototype: unsigned int __builtin_modud(unsigned long dividend,
unsigned int divisor);
Argument: dividendnumber to be divided
divisornumber to divide by
Return Value: Remainder.
Assembler Opera- modud
tor / Machine
Instruction:
Error Messages None.
__builtin_movsac
Description: Computes nothing, but prefetchs data ready for a future MAC
operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
If AWB is non null, the other accumulator will be written back into the
referenced variable.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
might generate:
movsac A, [w8]+=2, w4, [w10]+=2, w5
Prototype: int __builtin_movsac(
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB);
__builtin_movsac
Argument: xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Integer pointer to accumulator selection.
Return Value: Returns prefetch data.
Assembler Opera- movsac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_mpy
Description: Computes a x b ; also prefetchs data ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
might generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype: int __builtin_mpy(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr);
Argument: a Integer multiplicand.
b Integer multiplier.
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Integer pointer to accumulator selection.
Return Value: Returns the cleared value result to an accumulator.
Assembler Opera- mpy
tor / Machine
Instruction:
__builtin_mpy
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_mpyn
Description: Computes -a x b ; also prefetchs data ready for a future MAC
operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
might generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype: int __builtin_mpyn(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr);
Argument: aInteger multiplicand.
bInteger multiplier.
xptrInteger pointer to pointer to x prefetch.
xvalInteger pointer to value of x prefetch.
xincrInteger increment value of x prefetch.
yptrInteger pointer to pointer to y prefetch.
yvalInteger pointer to value of y prefetch.
yincrInteger increment value of y prefetch.
AWBInteger pointer to accumulator selection.
Return Value: Returns the cleared value result to an accumulator.
Assembler Opera- mpyn
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_msc
Description: Computes a x b and subtracts from accumulator; also prefetchs data
ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which
case the values of xincr and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which
case the values of yincr and yval are ignored, but required.
xval and yval nominate the address of a C variable where the
prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an
integer value.
If AWB is non null, the other accumulator will be written back into the
referenced variable.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
might generate:
msc w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype: int __builtin_msc(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB);
Argument: aInteger multiplicand.
bInteger multiplier.
xptrInteger pointer to pointer to x prefetch.
xvalInteger pointer to value of x prefetch.
xincrInteger increment value of x prefetch.
yptrInteger pointer to pointer to y prefetch.
yvalInteger pointer to value of y prefetch.
yincrInteger increment value of y prefetch.
AWBInteger pointer to accumulator selection.
Return Value: Returns the cleared value result to an accumulator.
Assembler Opera- msc
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_mulss
Description: Computes the product p0 x p1. Function arguments are signed inte-
gers, and the function result is a signed long integer. The command-line
option -Wconversions can be used to detect unexpected sign
conversions.
Prototype: signed long __builtin_mulss(const signed int p0,
const signed int p1);
__builtin_mulss
Argument: p0 multiplicand
p1 multiplier
Return Value: Returns the signed long integer value of the product p0 x p1.
Assembler Opera- mul.ss
tor / Machine
Instruction:
__builtin_mulsu
Description: Computes the product p0 x p1. Function arguments are integers with
mixed signs, and the function result is a signed long integer. The com-
mand-line option -Wconversions can be used to detect unexpected
sign conversions. This function supports the full range of addressing
modes of the instruction, including immediate mode for operand p1.
Prototype: signed long __builtin_mulsu(const signed int p0,
const unsigned int p1);
Argument: p0 multiplicand
p1 multiplier
Return Value: Returns the signed long integer value of the product p0 x p1.
Assembler Opera- mul.su
tor / Machine
Instruction:
__builtin_mulus
Description: Computes the product p0 x p1. Function arguments are integers with
mixed signs, and the function result is a signed long integer. The com-
mand-line option -Wconversions can be used to detect unexpected
sign conversions. This function supports the full range of addressing
modes of the instruction.
Prototype: signed long __builtin_mulus(const unsigned int p0,
const signed int p1);
Argument: p0 multiplicand
p1 multiplier
Return Value: Returns the signed long integer value of the product p0 x p1.
Assembler Opera- mul.us
tor / Machine
Instruction:
__builtin_muluu
Description: Computes the product p0 x p1. Function arguments are unsigned inte-
gers, and the function result is an unsigned long integer. The com-
mand-line option -Wconversions can be used to detect unexpected
sign conversions. This function supports the full range of addressing
modes of the instruction, including immediate mode for operand p1.
Prototype: unsigned long __builtin_muluu(const unsigned int p0,
const unsigned int p1);
Argument: p0 multiplicand
p1 multiplier
Return Value: Returns the signed long integer value of the product p0 x p1.
__builtin_muluu
Assembler Opera- mul.uu
tor / Machine
Instruction:
__builtin_nop
Description: Generates a nop instruction.
Prototype: void __builtin_nop(void);
Argument: None.
Return Value: Returns a no operation (nop).
Assembler Opera- nop
tor / Machine
Instruction:
__builtin_psvpage
Description: Returns the psv page number of the object whose address is given as a
parameter. The argument p must be the address of an object in an EE
data, PSV or executable memory space; otherwise an error message is
produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables”.
Prototype: unsigned int __builtin_psvpage(const void *p);
Argument: p object address
Return Value: Returns the psv page number of the object whose address is given as a
parameter.
Assembler Opera- psvpage
tor / Machine
Instruction:
Error Messages The following error message is produced when this function is used
incorrectly:
“Argument to __builtin_psvpage() is not the address of an object
in code, psv, or eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the
following syntax is valid:
unsigned page = __builtin_psvpage(&obj);
__builtin_psvoffset
Description: Returns the psv page offset of the object whose address is given as a
parameter. The argument p must be the address of an object in an EE
data, PSV or executable memory space; otherwise an error message is
produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables”.
Prototype: unsigned int __builtin_psvoffset(const void *p);
Argument: p object address
Return Value: Returns the psv page number offset of the object whose address is
given as a parameter.
Assembler Opera- psvoffset
tor / Machine
Instruction:
__builtin_psvoffset
Error Messages The following error message is produced when this function is used
incorrectly:
“Argument to __builtin_psvoffset() is not the address of an
object in code, psv, or eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the
following syntax is valid:
unsigned page = __builtin_psvoffset(&obj);
__builtin_readsfr
Description: Reads the SFR.
Prototype: unsigned int __builtin_readsfr(const void *p);
Argument: p object address
Return Value: Returns the SFR.
Assembler Opera- readsfr
tor / Machine
Instruction:
Error Messages The following error message is produced when this function is used
incorrectly:
__builtin_return_address
Description: Returns the return address of the current function, or of one of its call-
ers. For the level argument, a value of 0 yields the return address of
the current function, a value of 1 yields the return address of the caller
of the current function, and so forth. When level exceeds the current
stack depth, 0 will be returned. This function should only be used with a
non-zero argument for debugging purposes.
Prototype: int __builtin_return_address (const int level);
Argument: level Number of frames to scan up the call stack.
Return Value: Returns the return address of the current function, or of one of its call-
ers.
Assembler Opera- return_address
tor / Machine
Instruction:
__builtin_sac
Description: Shifts value by shift (a literal between -8 and 7) and returns the
value.
For example:
register int value asm("A");
int result;
result = __builtin_sac(value,3);
Might generate:
sac A, #3, w0
Prototype: int __builtin_sac(int value, int shift);
Argument: valueInteger number to be shifted.
shiftLiteral amount to shift.
Return Value: Returns the shifted result to an accumulator.
__builtin_sac
Assembler Opera- sac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_sacr
Description: Shifts value by shift (a literal between -8 and 7) and returns the value
which is rounded using the rounding mode determined by the
CORCONbits.RND control bit.
For example:
register int value asm("A");
int result;
result = __builtin_sac(value,3);
Might generate:
sac.r A, #3, w0
Prototype: int __builtin_sacr(int value, int shift);
Argument: valueInteger number to be shifted.
shiftLiteral amount to shift.
Return Value: Returns the shifted result to CORCON register.
Assembler Opera- sacr
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_sftac
Description: Shifts accumulator by shift. The valid shift range is -16 to 16.
For example:
register int result asm("A");
int i;
result = __builtin_sftac(i);
Might generate:
sftac A, w0
Prototype: int __builtin_sftac(int shift);
Argument: shiftLiteral amount to shift.
Return Value: Returns the shifted result to an accumulator.
Assembler Opera- sftac
tor / Machine
Instruction:
Error Messages An error message will be displayed if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_subab
Description: Subtracts acumulators A and B with the result written back to the
specified accumulator. For example:
register int result asm("A");
result = __builtin_subab();
will generate:
sub A
Prototype: int __builtin_subab(void);
Argument: None
Return Value: Returns the subtraction result to an accumulator.
Assembler Opera- subad
tor / Machine
Instruction:
Error Messages An error message will be displayed if the result is not an accumulator
register.
__builtin_tblpage
Description: Returns the table page number of the object whose address is given as
a parameter. The argument p must be the address of an object in an
EE data, PSV or executable memory space; otherwise an error mes-
sage is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables”.
Prototype: unsigned int __builtin_tblpage(const void *p);
Argument: p object address
Return Value: Returns the table page number of the object whose address is given as
a parameter.
Assembler Opera- tblpage
tor / Machine
Instruction:
Error Messages The following error message is produced when this function is used
incorrectly:
“Argument to __builtin_tblpage() is not the address of an object
in code, psv, or eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the
following syntax is valid:
unsigned page = __builtin_tblpage(&obj);
__builtin_tbloffset
Description: Returns the table page offset of the object whose address is given as a
parameter. The argument p must be the address of an object in an EE
data, PSV or executable memory space; otherwise an error message is
produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables”.
Prototype: unsigned int __builtin_tbloffset(const void *p);
Argument: p object address
Return Value: Returns the table page number offset of the object whose address is
given as a parameter.
__builtin_tbloffset
Assembler Opera- tbloffset
tor / Machine
Instruction:
Error Messages The following error message is produced when this function is used
incorrectly:
“Argument to __builtin_tbloffset() is not the address of an
object in code, psv, or eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the
following syntax is valid:
unsigned page = __builtin_tbloffset(&obj);
__builtin_tblrdh
Description: Issues the tblrdh.w instruction to read a word from Flash or EEDATA
memory. You must set up the TBLPAG to point to the appropriate page.
To do this, you may make use of __builtin_tbloffset() and
__builtin_tblpage().
Please refer to the data sheet or dsPIC Family Reference Manual for
complete details regarding reading and writing program Flash.
Prototype: unsigned int __builtin_tblrdh(unsigned int offset);
Argument: offset desired memory offset
Return Value: None.
Assembler Opera- tblrdh
tor / Machine
Instruction:
Error Messages None.
__builtin_tblrdl
Description: Issues the tblrdl.w instruction to read a word from Flash or EEDATA
memory. You must set up the TBLPAG to point to the appropriate page.
To do this, you may make use of __builtin_tbloffset()
and__builtin_tblpage().
Please refer to the data sheet or “dsPIC30F Family Reference Manual”
(DS70046) for complete details regarding reading and writing program
Flash.
Prototype: unsigned int __builtin_tblrdl(unsigned int offset);
Argument: offset desired memory offset
Return Value: None.
Assembler Opera- tblrdl
tor / Machine
Instruction:
Error Messages None.
__builtin_tblwth
Description: Issues the tblwth.w instruction to write a word to Flash or EEDATA
memory. You must set up the TBLPAG to point to the appropriate page.
To do this, you may make use of __builtin_tbloffset() and
__builtin_tblpage().
Please refer to the data sheet or “dsPIC30F Family Reference Manual”
(DS70046) for complete details regarding reading and writing program
Flash.
Prototype: void __builtin_tblwth(unsigned int offset
unsigned int data);
Argument: offset desired memory offset
data data to be written
Return Value: None.
Assembler Opera- tblwth
tor / Machine
Instruction:
Error Messages None.
__builtin_tblwtl
Description: Issues the tblrdl.w instruction to write a word to Flash or EEDATA
memory. You must set up the TBLPAG to point to the appropriate page.
To do this, you may make use of __builtin_tbloffset() and
__builtin_tblpage().
Please refer to the data sheet or “dsPIC30F Family Reference Manual”
(DS70046) for complete details regarding reading and writing program
Flash.
Prototype: void __builtin_tblwtl(unsigned int offset
unsigned int data);
Argument: offset desired memory offset
data data to be written
Return Value: None.
Assembler Opera- tblwtl
tor / Machine
Instruction:
Error Messages None.
__builtin_write_NVM
Description: Enables the Flash for writing by issuing the correct unlock sequence
and enabling the WRite bit of the NVMCON register.
Prototype: void __builtin_write_NVM(void);
Argument: None.
Return Value: None.
Assembler Opera- mov #0x55, Wn
tor / Machine mov Wn, _NVMKEY
Instruction: mov #0xAA, Wn
mov Wn, _NVMKEY
bset _NVMVON, #15
nop
nop
Error Messages None.
__builtin_write_RTCWEN
Description: Used to write to the RTCC Timer by implementing the unlock sequence
by writing the correct unlock values to NVMKEY and then setting the
RTCWREN bit of RCFGCAL SFR.
Prototype: void __builtin_write_RTCWEN(void);
Argument: None.
Return Value: None.
Assembler Opera- mov #0x55, Wn
tor / Machine mov Wn, _NVMKEY
Instruction: mov #0xAA, Wn
mov Wn, _NVMKEY
bset _NVMVON, #15
nop
nop
Error Messages None.
__builtin_write_OSCCONL
Description: Unlocks and writes its argument to OSCCONL.
Prototype: void __builtin_write_OSCCONL(unsigned char value);
Argument: value character to be written
Return Value: None.
Assembler Opera- mov #0x46, w0
tor / Machine mov #0x57, w1
Instruction*: mov __OSCCON, w2
mov.b w0, [w2]
mov.b w1, [w2]
mov.b value, [w2]
Error Messages None.
* The exact sequnce may be different.
__builtin_write_OSCCONH
Description: Unlocks and writes its argument to OSCCONH.
Prototype: void __builtin_write_OSCCONH(unsigned char value);
Argument: value character to be written
Return Value: None.
Assembler Opera- mov #0x78, w0
tor / Machine mov #0x9A, w1
Instruction*: mov __OSCCON+1, w2
mov.b w0, [w2]
mov.b w1, [w2]
mov.b value, [w2]
Error Messages None.
* The exact sequnce may be different.
Appendix C. Diagnostics
C.1 INTRODUCTION
This appendix lists the most common diagnostic messages generated by the MPLAB
C Compiler for PIC24 MCUs and dsPIC® DSCs (formerly MPLAB C30).
The compiler can produce two kinds of diagnostic messages: errors and warnings.
Each kind has a different purpose.
• Errors reports problems that make it impossible to compile your program. The
compiler reports errors with the source file name and line number where the prob-
lem is apparent.
• Warnings reports other unusual conditions in your code that may indicate a
problem, although compilation can (and does) proceed. Warning messages also
report the source file name and line number, but include the text warning: to dis-
tinguish them from error messages.
Warnings may indicate danger points where you should check to make sure that your
program really does what you intend; or the use of obsolete features; or the use of
non-standard features of the compiler. Many warnings are issued only if you ask for
them, with one of the -W options (for instance,-Wall requests a variety of useful
warnings).
In rare instances, the compiler may issue an internal error message report. This
signifies that the compiler itself has detected a fault that should be reported to
Microchip support. Details on contacting support are contained elsewhere in this
manual.
C.2 ERRORS
Symbols
\x used with no following HEX digits
The escape sequence \x should be followed by hex digits.
‘&’ constraint used with no register class
The asm statement is invalid.
‘%’ constraint used with last operand
The asm statement is invalid.
#elif after #else
In a preprocessor conditional, the #else clause must appear after any #elif clauses.
#elif without #if
In a preprocessor conditional, the #if must be used before using the #elif.
#else after #else
In a preprocessor conditional, the #else clause must appear only once.
#else without #if
In a preprocessor conditional, the #if must be used before using the #else.
A
a parameter list with an ellipsis can’t match an empty parameter name list
declaration
The declaration and definition of a function must be consistent.
“symbol” after #line is not a positive integer
#line is expecting a source line number which must be positive.
aggregate value used where a complex was expected
Do not use aggregate values where complex values are expected.
aggregate value used where a float was expected
Do not use aggregate values where floating-point values are expected.
aggregate value used where an integer was expected
Do not use aggregate values where integer values are expected.
alias arg not a string
The argument to the alias attribute must be a string that names the target for which the
current identifier is an alias.
alignment may not be specified for ‘identifier’
The aligned attribute may only be used with a variable.
‘__alignof’ applied to a bit-field
The ‘__alignof’ operator may not be applied to a bit-field.
alternate interrupt vector is not a constant
The interrupt vector number must be an integer constant.
alternate interrupt vector number n is not valid
A valid interrupt vector number is required.
B
bit-field ‘identifier’ has invalid type
Bit-fields must be of enumerated or integral type.
bit-field ‘identifier’ width not an integer constant
Bit-field widths must be integer constants.
both long and short specified for ‘identifier’
A variable cannot be of type long and of type short.
both signed and unsigned specified for ‘identifier’
A variable cannot be both signed and unsigned.
braced-group within expression allowed only inside a function
It is illegal to have a braced-group within expression outside a function.
break statement not within loop or switch
Break statements must only be used within a loop or switch.
__builtin_longjmp second argument must be 1
__builtin_longjmp requires its second argument to be 1.
C
called object is not a function
Only functions may be called in C.
cannot convert to a pointer type
The expression cannot be converted to a pointer type.
cannot put object with volatile field into register
It is not legal to put an object with a volatile field into a register.
cannot reload integer constant operand in ‘asm’
The asm statement is invalid.
cannot specify both near and far attributes
The attributes near and far are mutually exclusive, only one may be used for a function
or variable.
cannot take address of bit-field ‘identifier’
It is not legal to attempt to take address of a bit-field.
can’t open ‘file’ for writing
The system cannot open the specified ‘file’. Possible causes are not enough disk
space to open the file, the directory does not exist, or there is no write permission in the
destination directory.
can’t set ‘attribute’ attribute after definition
The ‘attribute’ attribute must be used when the symbol is defined.
case label does not reduce to an integer constant
Case labels must be compile-time integer constants.
case label not within a switch statement
Case labels must be within a switch statement.
cast specifies array type
It is not permissible for a cast to specify an array type.
D
data type of ‘name’ isn’t suitable for a register
The data type does not fit into the requested register.
declaration for parameter ‘identifier’ but no such parameter
Only parameters in the parameter list may be declared.
declaration of ‘identifier’ as array of functions
It is not legal to have an array of functions.
declaration of ‘identifier’ as array of voids
It is not legal to have an array of voids.
‘identifier’ declared as function returning a function
Functions may not return functions.
‘identifier’ declared as function returning an array
Functions may not return arrays.
decrement of pointer to unknown structure
Do not decrement a pointer to an unknown structure.
‘default’ label not within a switch statement
Default case labels must be within a switch statement.
‘symbol’ defined both normally and as an alias
A ‘symbol’ can not be used as an alias for another symbol if it has already been
defined.
‘defined’ cannot be used as a macro name
The macro name cannot be called ‘defined’.
dereferencing pointer to incomplete type
A dereferenced pointer must be a pointer to an incomplete type.
division by zero in #if
Division by zero is not computable.
E
elements of array ‘identifier’ have incomplete type
Array elements should have complete types.
empty character constant
Empty character constants are not legal.
empty file name in ‘#keyword’
The filename specified as an argument of the specified #keyword is empty.
empty index range in initializer
Do not use empty index ranges in initializers
empty scalar initializer
Scalar initializers must not be empty.
enumerator value for ‘identifier’ not integer constant
Enumerator values must be integer constants.
error closing ‘file’
The system cannot close the specified ‘file’. Possible causes are not enough disk
space to write to the file or the file is too big.
error writing to ‘file’
The system cannot write to the specified ‘file’. Possible causes are not enough disk
space to write to the file or the file is too big.
excess elements in char array initializer
There are more elements in the list than the initializer value states.
excess elements in struct initializer
Do not use excess elements in structure initializers.
expression statement has incomplete type
The type of the expression is incomplete.
extra brace group at end of initializer
Do not place extra brace groups at the end of initializers.
extraneous argument to ‘option’ option
There are too many arguments to the specified command-line option.
F
‘identifier’ fails to be a typedef or built in type
A data type must be a typedef or built-in type.
field ‘identifier’ declared as a function
Fields may not be declared as functions.
field ‘identifier’ has incomplete type
Fields must have complete types.
first argument to __builtin_choose_expr not a constant
The first argument must be a constant expression that can be determined at compile
time.
flexible array member in otherwise empty struct
A flexible array member must be the last element of a structure with more than one
named member.
flexible array member in union
A flexible array member cannot be used in a union.
flexible array member not at end of struct
A flexible array member must be the last element of a structure.
‘for’ loop initial declaration used outside C99 mode
A ‘for’ loop initial declaration is not valid outside C99 mode.
format string arg follows the args to be formatted
The arguments to the format attribute are inconsistent. The format string argument
index must be less than the index of the first argument to check.
format string arg not a string type
The format string index argument of the format attribute specifies a parameter which is
not a string type.
format string has invalid operand number
The operand number argument of the format attribute must be a compile-time constant.
function definition declared ‘register’
Function definitions may not be declared ‘register’.
function definition declared ‘typedef’
Function definitions may not be declared ‘typedef’.
function does not return string type
The format_arg attribute may only be used with a function which return value is a string
type.
function ‘identifier’ is initialized like a variable
It is not legal to initialize a function like a variable.
function return type cannot be function
The return type of a function cannot be a function.
G
global register variable follows a function definition
Global register variables should precede function definitions.
global register variable has initial value
Do not specify an initial value for a global register variable.
global register variable ‘identifier’ used in nested function
Do not use a global register variable in a nested function.
H
‘identifier’ has an incomplete type
It is not legal to have an incomplete type for the specified ‘identifier’.
‘identifier’ has both ‘extern’ and initializer
A variable declared ‘extern’ cannot be initialized.
hexadecimal floating constants require an exponent
Hexadecimal floating constants must have exponents.
I
implicit declaration of function ‘identifier’
The function identifier is used without a preceding prototype declaration or function
definition.
impossible register constraint in ‘asm’
The asm statement is invalid.
incompatible type for argument n of ‘identifier’
When calling functions in C, ensure that actual argument types match the formal
parameter types.
incompatible type for argument n of indirect function call
When calling functions in C, ensure that actual argument types match the formal
parameter types.
incompatible types in operation
The types used in operation must be compatible.
incomplete ‘name’ option
The option to the command-line parameter name is incomplete.
inconsistent operand constraints in an ‘asm’
The asm statement is invalid.
increment of pointer to unknown structure
Do not increment a pointer to an unknown structure.
initializer element is not computable at load time
Initializer elements must be computable at load time.
initializer element is not constant
Initializer elements must be constant.
initializer fails to determine size of ‘identifier’
An array initializer fails to determine its size.
L
label label referenced outside of any function
Labels may only be referenced inside functions.
label ‘label’ used but not defined
The specified label is used but is not defined.
language ‘name’ not recognized
Permissible languages include: c assembler none.
filename: linker input file unused because linking not done
The specified filename was specified on the command line, and it was taken to be a
linker input file (since it was not recognized as anything else). However, the link step
was not run. Therefore, this file was ignored.
long long long is too long for GCC
The compiler supports integers no longer than long long.
long or short specified with char for ‘identifier’
The long and short qualifiers cannot be used with the char type.
long or short specified with floating type for ‘identifier’
The long and short qualifiers cannot be used with the float type.
long, short, signed or unsigned invalid for ‘identifier’
The long, short and signed qualifiers may only be used with integral types.
M
macro names must be identifiers
Macro names must start with a letter or underscore followed by more letters, numbers
or underscores.
macro parameters must be comma-separated
Commas are required between parameters in a list of parameters.
macro ‘name’ passed n arguments, but takes just n
Too many arguments were passed to macro ‘name’.
N
negative width in bit-field ‘identifier’
Bit-field widths may not be negative.
nested function ‘name’ declared ‘extern’
A nested function cannot be declared ‘extern’.
nested redefinition of ‘identifier’
Nested redefinitions are illegal.
no data type for mode ‘mode’
The argument mode specified for the mode attribute is a recognized GCC machine
mode, but it is not one that is implemented in the compiler.
no include path in which to find ‘name’
Cannot find include file ‘name’.
no macro name given in #‘directive’ directive
A macro name must follow the #define, #undef, #ifdef or #ifndef directives.
nonconstant array index in initializer
Only constant array indices may be used in initializers.
non-prototype definition here
If a function prototype follows a definition without a prototype, and the number of
arguments is inconsistent between the two, this message identifies the line number of
the non-prototype definition.
number of arguments doesn’t match prototype
The number of function arguments must match the function’s prototype.
O
operand constraint contains incorrectly positioned ‘+’ or ‘=’.
The asm statement is invalid.
operand constraints for ‘asm’ differ in number of alternatives
The asm statement is invalid.
operator “defined” requires an identifier
“defined” is expecting an identifier.
operator ‘symbol’ has no right operand
Preprocessor operator ‘symbol’ requires an operand on the right side.
output number n not directly addressable
The asm statement is invalid.
output operand constraint lacks ‘=’
The asm statement is invalid.
output operand is constant in ‘asm’
The asm statement is invalid.
overflow in enumeration values
Enumeration values must be in the range of ‘int’.
P
parameter ‘identifier’ declared void
Parameters may not be declared void.
parameter ‘identifier’ has incomplete type
Parameters must have complete types.
parameter ‘identifier’ has just a forward declaration
Parameters must have complete types; forward declarations are insufficient.
parameter ‘identifier’ is initialized
It is lot legal to initialize parameters.
parameter name missing
The macro was expecting a parameter name. Check for two commas without a name
between.
parameter name missing from parameter list
Parameter names must be included in the parameter list.
parameter name omitted
Parameter names may not be omitted.
param types given both in param list and separately
Parameter types should be given either in the parameter list or separately, but not both.
parse error
The source line cannot be parsed; it contains errors.
pointer value used where a complex value was expected
Do not use pointer values where complex values are expected.
pointer value used where a floating point value was expected
Do not use pointer values where floating-point values are expected.
pointers are not permitted as case values
A case value must be an integer-valued constant or constant expression.
predicate must be an identifier
#assert or #unassert require a single identifier as the predicate.
predicate’s answer is empty
The #assert or #unassert has a predicate and parentheses but no answer inside the
parentheses, which is required.
previous declaration of ‘identifier’
This message identifies the location of a previous declaration of identifier that conflicts
with the current declaration.
identifier previously declared here
This message identifies the location of a previous declaration of identifier that conflicts
with the current declaration.
identifier previously defined here
This message identifies the location of a previous definition of identifier that conflicts
with the current definition.
prototype declaration
Identifies the line number where a function prototype is declared. Used in conjunction
with other error messages.
R
redeclaration of ‘identifier’
The identifier is multiply declared.
redeclaration of ‘enum identifier’
Enums may not be redeclared.
‘identifier’ redeclared as different kind of symbol
Multiple, inconsistent declarations exist for identifier.
redefinition of ‘identifier’
The identifier is multiply defined.
redefinition of ‘struct identifier’
Structs may not be redefined.
redefinition of ‘union identifier’
Unions may not be redefined.
register name given for non-register variable ‘name’
Attempt to map a register to a variable which is not marked as register.
register name not specified for ‘name’
File scope variable ‘name’ declared as a register variable without providing a register.
register specified for ‘name’ isn’t suitable for data type
Alignment or other restrictions prevent using requested register.
request for member ‘identifier’ in something not a structure or union
Only structure or unions have members. It is not legal to reference a member of
anything else, since nothing else has members.
requested alignment is not a constant
The argument to the aligned attribute must be a compile-time constant.
requested alignment is not a power of 2
The argument to the aligned attribute must be a power of two.
requested alignment is too large
The alignment size requested is larger than the linker allows. The size must be 4096
or less and a power of 2.
return type is an incomplete type
Return types must be complete.
S
save variable ‘name’ index not constant
The subscript of the array ‘name’ is not a constant integer.
save variable ‘name’ is not word aligned
The object being saved must be word aligned
save variable ‘name’ size is not even
The object being saved must be evenly sized.
save variable ‘name’ size is not known
The object being saved must have a known size.
T
the only valid combination is ‘long double’
The long qualifier is the only qualifier that may be used with the double type.
this built-in requires a frame pointer
__builtin_return_address requires a frame pointer. Do not use the
-fomit-frame-pointer option.
this is a previous declaration
If a label is duplicated, this message identifies the line number of a preceding
declaration.
too few arguments to function
When calling a function in C, do not specify fewer arguments than the function requires.
Nor should you specify too many.
too few arguments to function ‘identifier’
When calling a function in C, do not specify fewer arguments than the function requires.
Nor should you specify too many.
too many alternatives in ‘asm’
The asm statement is invalid.
too many arguments to function
When calling a function in C, do not specify more arguments than the function requires.
Nor should you specify too few.
too many arguments to function ‘identifier’
When calling a function in C, do not specify more arguments than the function requires.
Nor should you specify too few.
too many decimal points in number
Expecting only one decimal point.
top-level declaration of ‘identifier’ specifies ‘auto’
Auto variables can only be declared inside functions.
two or more data types in declaration of ‘identifier’
Each identifier may have only a single data type.
two types specified in one empty declaration
No more that one type should be specified.
type of formal parameter n is incomplete
Specify a complete type for the indicated parameter.
type mismatch in conditional expression
Types in conditional expressions must not be mismatched.
typedef ‘identifier’ is initialized
It is not legal to initialize typedef’s. Use __typeof__ instead.
U
‘identifier’ undeclared (first use in this function)
The specified identifier must be declared.
‘identifier’ undeclared here (not in a function)
The specified identifier must be declared.
union has no member named ‘identifier’
A union member named ‘identifier’ is referenced, but the referenced union contains no
such member. This is not allowed.
unknown field ‘identifier’ specified in initializer
Do not use unknown fields in initializers.
unknown machine mode ‘mode’
The argument mode specified for the mode attribute is not a recognized machine
mode.
unknown register name ‘name’ in ‘asm’
The asm statement is invalid.
unrecognized format specifier
The argument to the format attribute is invalid.
unrecognized option ‘-option’
The specified command-line option is not recognized.
unrecognized option ‘option’
‘option’ is not a known option.
‘identifier’ used prior to declaration
The identifier is used prior to its declaration.
unterminated #‘name’
#endif is expected to terminate a #if, #ifdef or #ifndef conditional.
unterminated argument list invoking macro ‘name’
Evaluation of a function macro has encountered the end of file before completing the
macro expansion.
unterminated comment
The end of file was reached while scanning for a comment terminator.
V
‘va_start’ used in function with fixed args
‘va_start’ should be used only in functions with variable argument lists.
variable ‘identifier’ has initializer but incomplete type
It is not legal to initialize variables with incomplete types.
variable or field ‘identifier’ declared void
Neither variables nor fields may be declared void.
variable-sized object may not be initialized
It is not legal to initialize a variable-sized object.
virtual memory exhausted
Not enough memory left to write error message.
W
warning: -pipe ignored because -save-temps specified
The -pipe option cannot be used with the -save-temps option.
warning: -pipe ignored because -time specified
The -pipe option cannot be used with the -time option.
warning: ‘-x spec’ after last input file has no effect
The ‘-x’ command line option affects only those files named after its on the command
line; if there are no such files, then this option has no effect.
weak declaration of ‘name’ must be public
Weak symbols must be externally visible.
weak declaration of ‘name’ must precede definition
‘name’ was defined and then declared weak.
wrong number of arguments specified for attribute attribute
There are too few or too many arguments given for the attribute named ‘attribute’.
wrong type argument to bit-complement
Do not use the wrong type of argument to this operator.
wrong type argument to decrement
Do not use the wrong type of argument to this operator.
wrong type argument to increment
Do not use the wrong type of argument to this operator.
wrong type argument to unary exclamation mark
Do not use the wrong type of argument to this operator.
wrong type argument to unary minus
Do not use the wrong type of argument to this operator.
wrong type argument to unary plus
Do not use the wrong type of argument to this operator.
Z
zero width for bit-field ‘identifier’
Bit-fields may not have zero width.
C.3 WARNINGS
Symbols
‘/*’ within comment
A comment mark was found within a comment.
‘$’ character(s) in identifier or number
Dollar signs in identifier names are an extension to the standard.
#‘directive’ is a GCC extension
#warning, #include_next, #ident, #import, #assert and #unassert directives are GCC
extensions and are not of ISO C89.
#import is obsolete, use an #ifndef wrapper in the header file
The #import directive is obsolete. #import was used to include a file if it hadn’t already
been included. Use the #ifndef directive instead.
#include_next in primary source file
#include_next starts searching the list of header file directories after the directory in
which the current file was found. In this case, there were no previous header files so it
is starting in the primary source file.
#pragma pack (pop) encountered without matching #pragma pack (push, <n>)
The pack(pop) pragma must be paired with a pack(push) pragma, which must precede
it in the source file.
#pragma pack (pop, identifier) encountered without matching #pragma pack
(push, identifier, <n>)
The pack(pop) pragma must be paired with a pack(push) pragma, which must precede
it in the source file.
#warning: message
The directive #warning causes the preprocessor to issue a warning and continue
preprocessing. The tokens following #warning are used as the warning message.
A
absolute address specification ignored
Ignoring the absolute address specification for the code section in the #pragma
statement because it is not supported in the compiler. Addresses must be specified in
the linker script and code sections can be defined with the keyword __attribute__.
address of register variable ‘name’ requested
The register specifier prevents taking the address of a variable.
alignment must be a small power of two, not n
The alignment parameter of the pack pragma must be a small power of two.
anonymous enum declared inside parameter list
An anonymous enum is declared inside a function parameter list. It is usually better
programming practice to declare enums outside parameter lists, since they can never
become complete types when defined inside parameter lists.
anonymous struct declared inside parameter list
An anonymous struct is declared inside a function parameter list. It is usually better
programming practice to declare structs outside parameter lists, since they can never
become complete types when defined inside parameter lists.
B
backslash and newline separated by space
While processing for escape sequences, a backslash and newline were found
separated by a space.
backslash-newline at end of file
While processing for escape sequences, a backslash and newline were found at the
end of the file.
bit-field ‘identifier’ type invalid in ISO C
The type used on the specified identifier is not valid in ISO C.
braces around scalar initializer
A redundant set of braces around an initializer is supplied.
C
C++ style comments are not allowed in ISO C89
Use C style comments ‘/*’ and ‘*/’ instead of C++ style comments ‘//’.
call-clobbered register used for global register variable
Choose a register that is normally saved and restored by function calls (W8-W13), so
that library routines will not clobber it.
cannot inline function ‘main’
The function ‘main’ is declared with the inline attribute. This is not supported, since
main must be called from the C start-up code, which is compiled separately.
can’t inline call to ‘identifier’ called from here
The compiler was unable to inline the call to the specified function.
case value ‘n’ not in enumerated type
The controlling expression of a switch statement is an enumeration type, yet a case
expression has the value n, which does not correspond to any of the enumeration
values.
case value ‘value’ not in enumerated type ‘name’
‘value’ is an extra switch case that is not an element of the enumerated type ‘name’.
cast does not match function type
The return type of a function is cast to a type that does not match the function’s type.
cast from pointer to integer of different size
A pointer is cast to an integer that is not 16-bits wide.
cast increases required alignment of target type
When compiling with the -Wcast-align command-line option, the compiler verifies
that casts do not increase the required alignment of the target type. For example, this
warning message will be given if a pointer to char is cast as a pointer to int, since the
aligned for char (byte alignment) is less than the alignment requirement for int (word
alignment).
character constant too long
Character constants must not be too long.
comma at end of enumerator list
Unnecessary comma at the end of the enumerator list.
comma operator in operand of #if
Not expecting a comma operator in the #if directive.
comparing floating point with == or != is unsafe
Floating-point values can be approximations to infinitely precise real numbers. Instead
of testing for equality, use relational operators to see whether the two values have
ranges that overlap.
comparison between pointer and integer
A pointer type is being compared to an integer type.
D
data definition has no type or storage class
A data definition was detected that lacked a type and storage class.
data qualifier ‘qualifier’ ignored
Data qualifiers, which include ‘access’, ‘shared’ and ‘overlay’, are not used in the com-
piler, but are there for compatibility with the MPLAB C Compiler for PIC18 MCUs.
declaration of ‘identifier’ has ‘extern’ and is initialized
Externs should not be initialized.
declaration of ‘identifier’ shadows a parameter
The specified identifier declaration shadows a parameter, making the parameter
inaccessible.
declaration of ‘identifier’ shadows a symbol from the parameter list
The specified identifier declaration shadows a symbol from the parameter list, making
the symbol inaccessible.
declaration of ‘identifier’ shadows global declaration
The specified identifier declaration shadows a global declaration, making the global
inaccessible.
‘identifier’ declared inline after being called
The specified function was declared inline after it was called.
‘identifier’ declared inline after its definition
The specified function was declared inline after it was defined.
‘identifier’ declared ‘static’ but never defined
The specified function was declared static, but was never defined.
decrement of read-only member ‘name’
The member ‘name’ was declared as const and cannot be modified by decrementing.
decrement of read-only variable ‘name’
‘name’ was declared as const and cannot be modified by decrementing.
‘identifier’ defined but not used
The specified function was defined, but was never used.
deprecated use of label at end of compound statement
A label should not be at the end of a statement. It should be followed by a statement.
dereferencing ‘void *’ pointer
It is not correct to dereference a ‘void *’ pointer. Cast it to a pointer of the appropriate
type before dereferencing the pointer.
division by zero
Compile-time division by zero has been detected.
E
embedded ‘\0’ in format
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the format string contains an embedded ‘\0’ (zero), which can cause early termination
of format string processing.
empty body in an else-statement
An else statement is empty.
empty body in an if-statement
An if statement is empty.
empty declaration
The declaration contains no names to declare.
empty range specified
The range of values in a case range is empty, that is, the value of the low expression
is greater than the value of the high expression. Recall that the syntax for case ranges
is case low ... high:.
‘enum identifier’ declared inside parameter list
The specified enum is declared inside a function parameter list. It is usually better
programming practice to declare enums outside parameter lists, since they can never
become complete types when defined inside parameter lists.
enum defined inside parms
An enum is defined inside a function parameter list.
enumeration value ‘identifier’ not handled in switch
The controlling expression of a switch statement is an enumeration type, yet not all
enumeration values have case expressions.
enumeration values exceed range of largest integer
Enumeration values are represented as integers. The compiler detected that an
enumeration range cannot be represented in any of the compiler integer formats,
including the largest such format.
excess elements in array initializer
There are more elements in the initializer list than the array was declared with.
excess elements in scalar initializer");
There should be only one initializer for a scalar variable.
excess elements in struct initializer
There are more elements in the initializer list than the structure was declared with.
excess elements in union initializer
There are more elements in the initializer list than the union was declared with.
F
-ffunction-sections may affect debugging on some targets
You may have problems with debugging if you specify both the -g option and the
-ffunction-sections option.
first argument of ‘identifier’ should be ‘int’
Expecting declaration of first argument of specified identifier to be of type int.
floating constant exceeds range of ‘double’
A floating-point constant is too large or too small (in magnitude) to be represented as
a ‘double’.
floating constant exceeds range of ‘float’
A floating-point constant is too large or too small (in magnitude) to be represented as
a ‘float’.
floating constant exceeds range of ‘long double’
A floating-point constant is too large or too small (in magnitude) to be represented as
a ‘long double’.
floating point overflow in expression
When folding a floating-point constant expression, the compiler found that the
expression overflowed, that is, it could not be represented as float.
‘type1’ format, ‘type2’ arg (arg ‘num’)
The format is of type ‘type1’, but the argument being passed is of type ‘type2’.
The argument in question is the ‘num’ argument.
format argument is not a pointer (arg n)
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the specified argument number n was not a pointer, san the format specifier indicated
it should be.
format argument is not a pointer to a pointer (arg n)
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the specified argument number n was not a pointer san the format specifier indicated
it should be.
fprefetch-loop-arrays not supported for this target
The option to generate instructions to prefetch memory is not supported for this target.
function call has aggregate value
The return value of a function is an aggregate.
function declaration isn’t a prototype
When compiling with the -Wstrict-prototypes command-line option, the compiler
ensures that function prototypes are specified for all functions. In this case, a function
definition was encountered without a preceding function prototype.
function declared ‘noreturn’ has a ‘return’ statement
A function was declared with the noreturn attribute-indicating that the function does not
return-yet the function contains a return statement. This is inconsistent.
G
GCC does not yet properly implement ‘[*]’ array declarators
Variable length arrays are not currently supported by the compiler.
H
hex escape sequence out of range
The hex sequence must be less than 100 in hex (256 in decimal).
I
ignoring asm-specifier for non-static local variable ‘identifier’
The asm-specifier is ignored when it is used with an ordinary, non-register local
variable.
ignoring invalid multibyte character
When parsing a multibyte character, the compiler determined that it was invalid. The
invalid character is ignored.
ignoring option ‘option’ due to invalid debug level specification
A debug option was used with a debug level that is not a valid debug level.
ignoring #pragma identifier
The specified pragma is not supported by the compiler, and is ignored.
imaginary constants are a GCC extention
ISO C does not allow imaginary numeric constants.
implicit declaration of function ‘identifier’
The specified function has no previous explicit declaration (definition or function
prototype), so the compiler makes assumptions about its return type and parameters.
L
label ‘identifier’ defined but not used
The specified label was defined, but not referenced.
large integer implicitly truncated to unsigned type
An integer constant value appears in the source code without an explicit unsigned
modifier, yet the number cannot be represented as a signed int; therefore, the compiler
automatically treats it as an unsigned int.
left-hand operand of comma expression has no effect
One of the operands of a comparison is a promoted ~unsigned, while the other is
unsigned.
left shift count >= width of type
Shift counts should be less than the number of bits in the type being shifted. Otherwise,
the shift is meaningless, and the result is undefined.
left shift count is negative
Shift counts should be positive. A negative left shift count does not mean shift right;
it is meaningless.
M
‘main’ is usually a function
The identifier main is usually used for the name of the main entry point of an
application. The compiler detected that it was being used in some other way, for
example, as the name of a variable.
‘operation’ makes integer from pointer without a cast
A pointer has been implicitly converted to an integer.
‘operation’ makes pointer from integer without a cast
An integer has been implicitly converted to a pointer.
malformed ‘#pragma pack-ignored’
The syntax of the pack pragma is incorrect.
malformed ‘#pragma pack(pop[,id])-ignored’
The syntax of the pack pragma is incorrect.
malformed ‘#pragma pack(push[,id],<n>)-ignored’
The syntax of the pack pragma is incorrect.
malformed ‘#pragma weak-ignored’
The syntax of the weak pragma is incorrect.
‘identifier’ might be used uninitialized in this function
The compiler detected a control path though a function which might use the specified
identifier before it has been initialized.
missing braces around initializer
A required set of braces around an initializer is missing.
missing initializer
An initializer is missing.
modification by ‘asm’ of read-only variable ‘identifier’
A const variable is the left-hand-side of an assignment in an ‘asm’ statement.
multi-character character constant
A character constant contains more than one character.
N
negative integer implicitly converted to unsigned type
A negative integer constant value appears in the source code, but the number cannot
be represented as a signed int; therefore, the compiler automatically treats it as an
unsigned int.
nested extern declaration of ‘identifier’
There are nested extern definitions of the specified identifier.
no newline at end of file
The last line of the source file is not terminated with a newline character.
no previous declaration for ‘identifier’
When compiling with the -Wmissing-declarations command-line option, the
compiler ensures that functions are declared before they are defined. In this case, a
function definition was encountered without a preceding function declaration.
no previous prototype for ‘identifier’
When compiling with the -Wmissing-prototypes command-line option, the
compiler ensures that function prototypes are specified for all functions. In this case, a
function definition was encountered without a preceding function prototype.
no semicolon at end of struct or union
A semicolon is missing at the end of the structure or union declaration.
non-ISO-standard escape sequence, ‘seq’
‘seq’ is ‘\e’ or ‘\E’ and is an extension to the ISO standard. The sequence can be used
in a string or character constant and stands for the ASCII character <ESC>.
non-static declaration for ‘identifier’ follows static
The specified identifier was declared non-static after it was previously declared as
static.
‘noreturn’ function does return
A function declared with the noreturn attribute returns. This is inconsistent.
‘noreturn’ function returns non-void value
A function declared with the noreturn attribute returns a non-void value. This is
inconsistent.
null format string
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the format string was missing.
O
octal escape sequence out of range
The octal sequence must be less than 400 in octal (256 in decimal).
output constraint ‘constraint’ for operand n is not at the beginning
Output constraints in extended asm should be at the beginning.
overflow in constant expression
The constant expression has exceeded the range of representable values for its type.
overflow in implicit constant conversion
An implicit constant conversion resulted in a number that cannot be represented as a
signed int; therefore, the compiler automatically treats it as an unsigned int.
P
parameter has incomplete type
A function parameter has an incomplete type.
parameter names (without types) in function declaration
The function declaration lists the names of the parameters but not their types.
parameter points to incomplete type
A function parameter points to an incomplete type.
parameter ‘identifier’ points to incomplete type
The specified function parameter points to an incomplete type.
passing arg ‘number’ of ‘name’ as complex rather than floating due to prototype
The prototype declares argument ‘number’ as a complex, but a float value is used so
the compiler converts to a complex to agree with the prototype.
passing arg ‘number’ of ‘name’ as complex rather than integer due to prototype
The prototype declares argument ‘number’ as a complex, but an integer value is used
so the compiler converts to a complex to agree with the prototype.
passing arg ‘number’ of ‘name’ as floating rather than complex due to prototype
The prototype declares argument ‘number’ as a float, but a complex value is used so
the compiler converts to a float to agree with the prototype.
passing arg ‘number’ of ‘name’ as ‘float’ rather than ‘double’ due to prototype
The prototype declares argument ‘number’ as a float, but a double value is used so the
compiler converts to a float to agree with the prototype.
passing arg ‘number’ of ‘name’ as floating rather than integer due to prototype
The prototype declares argument ‘number’ as a float, but an integer value is used so
the compiler converts to a float to agree with the prototype.
passing arg ‘number’ of ‘name’ as integer rather than complex due to prototype
The prototype declares argument ‘number’ as an integer, but a complex value is used
so the compiler converts to an integer to agree with the prototype.
passing arg ‘number’ of ‘name’ as integer rather than floating due to prototype
The prototype declares argument ‘number’ as an integer, but a float value is used so
the compiler converts to an integer to agree with the prototype.
pointer of type ‘void *’ used in arithmetic
A pointer of type ‘void’ has no size and should not be used in arithmetic.
pointer to a function used in arithmetic
A pointer to a function should not be used in arithmetic.
previous declaration of ‘identifier’
This warning message appears in conjunction with another warning message. The
previous message identifies the location of the suspect code. This message identifies
the first declaration or definition of the identifier.
previous implicit declaration of ‘identifier’
This warning message appears in conjunction with the warning message “type
mismatch with previous implicit declaration”. It locates the implicit declaration of the
identifier that conflicts with the explicit declaration.
R
“name” re-asserted
The answer for "name" has been duplicated.
“name” redefined
“name” was previously defined and is being redefined now.
redefinition of ‘identifier’
The specified identifier has multiple, incompatible definitions.
redundant redeclaration of ‘identifier’ in same scope
The specified identifier was re-declared in the same scope. This is redundant.
register used for two global register variables
Two global register variables have been defined to use the same register.
repeated ‘flag’ flag in format
When checking the argument list of a call to strftime, the compiler found that there was
a flag in the format string that is repeated.
When checking the argument list of a call to printf, scanf, etc., the compiler found that
one of the flags { ,+,#,0,-} was repeated in the format string.
return-type defaults to ‘int’
In the absence of an explicit function return-type declaration, the compiler assumes
that the function returns an int.
return type of ‘name’ is not ‘int’
The compiler is expecting the return type of ‘name’ to be ‘int’.
‘return’ with a value, in function returning void
The function was declared as void but returned a value.
‘return’ with no value, in function returning non-void
A function declared to return a non-void value contains a return statement with no
value. This is inconsistent.
right shift count >= width of type
Shift counts should be less than the number of bits in the type being shifted. Otherwise,
the shift is meaningless, and the result is undefined.
right shift count is negative
Shift counts should be positive. A negative right shift count does not mean shift left; it
is meaningless.
S
second argument of ‘identifier’ should be ‘char **’
Expecting second argument of specified identifier to be of type ‘char **’.
second parameter of ‘va_start’ not last named argument
The second parameter of ‘va_start’ must be the last named argument.
shadowing built-in function ‘identifier’
The specified function has the same name as a built-in function, and consequently
shadows the built-in function.
shadowing library function ‘identifier’
The specified function has the same name as a library function, and consequently
shadows the library function.
T
‘identifier’ takes only zero or two arguments
Expecting zero or two arguments only.
the meaning of ‘\a’ is different in traditional C
When the -wtraditional option is used, the escape sequence ‘\a’ is not recognized
as a meta-sequence: its value is just ‘a’. In non-traditional compilation, ‘\a’ represents
the ASCII BEL character.
the meaning of ‘\x’ is different in traditional C
When the -wtraditional option is used, the escape sequence ‘\x’ is not recognized
as a meta-sequence: its value is just ‘x’. In non-traditional compilation, ‘\x’ introduces
a hexadecimal escape sequence.
third argument of ‘identifier’ should probably be ‘char **’
Expecting third argument of specified identifier to be of type ‘char **’.
this function may return with or without a value
All exit paths from non-void function should return an appropriate value. The compiler
detected a case where a non-void function terminates, sometimes with and sometimes
without an explicit return value. Therefore, the return value might be unpredictable.
this target machine does not have delayed branches
The -fdelayed-branch option is not supported.
too few arguments for format
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the number of actual arguments was fewer than that required by the format string.
U
undefining ‘defined’
‘defined’ cannot be used as a macro name and should not be undefined.
undefining ‘name’
The #undef directive was used on a previously defined macro name ‘name’.
union cannot be made transparent
The transparent_union attribute was applied to a union, but the specified variable
does not satisfy the requirements of that attribute.
‘union identifier’ declared inside parameter list
The specified union is declared inside a function parameter list. It is usually better
programming practice to declare unions outside parameter lists, since they can never
become complete types when defined inside parameter lists.
V
__VA_ARGS__ can only appear in the expansion of a C99 variadic macro
The predefined macro __VA_ARGS should be used in the substitution part of a macro
definition using ellipses.
value computed is not used
A value computed is not used.
variable ‘name’ declared ‘inline’
The keyword ‘inline’ should be used with functions only.
variable ‘%s’ might be clobbered by ‘longjmp’ or ‘vfork’
A non-volatile automatic variable might be changed by a call to longjmp. These
warnings are possible only in optimizing compilation.
volatile register variables don’t work as you might wish
Passing a variable as an argument could transfer the variable to a different register
(w0-w7) than the one specified (if not w0-w7) for argument transmission. Or the
compiler may issue an instruction that is not suitable for the specified register and may
need to temporarily move the value to another place. These are only issues if the
specified register is modified asynchronously (i.e., though an ISR).
W
-Wformat-extra-args ignored without -Wformat
-Wformat must be specified to use -Wformat-extra-args.
-Wformat-nonliteral ignored without -Wformat
-Wformat must be specified to use -Wformat-nonliteral.
-Wformat-security ignored without -Wformat
-Wformat must be specified to use -Wformat-security.
-Wformat-y2k ignored without -Wformat
-Wformat must be specified to use.
-Wid-clash-LEN is no longer supported
The option -Wid-clash-LEN is no longer supported.
-Wmissing-format-attribute ignored without -Wformat
-Wformat must be specified to use -Wmissing-format-attribute.
-Wuninitialized is not supported without -O
Optimization must be on to use the -Wuninitialized option.
‘identifier’ was declared ‘extern’ and later ‘static’
The specified identifier was previously declared ‘extern’ and is now being declared as
static.
‘identifier’ was declared implicitly ‘extern’ and later ‘static’
The specified identifier was previously declared implicitly ‘extern’ and is now being
declared as static.
‘identifier’ was previously implicitly declared to return ‘int’
There is a mismatch against the previous implicit declaration.
Z
zero-length identifier format string
When checking the argument list of a call to printf, scanf, etc., the compiler found that
the format string was empty (“”).
D.1 INTRODUCTION
The purpose of this chapter is to highlight the differences between the MPLAB C Com-
piler for PIC18 MCUs (formerly MPLAB C18) and the MPLAB C C Compiler for PIC24
MCUs and dsPIC® DSCs (formerly MPLAB C30). For more details on the PIC18 MCU
compiler, please refer to the “MPLAB® C18 C Compiler User’s Guide” (DS51288).
D.2 HIGHLIGHTS
This chapter discusses the following areas of difference between the two compilers:
• Data Formats
• Pointers
• Storage Classes
• Stack Usage
• Storage Qualifiers
• Predefined Macro Names
• Integer Promotions
• String Constants
• Access Memory
• Inline Assembly
• Pragmas
• Memory Models
• Calling Conventions
• Startup Code
• Compiler-Managed Resources
• Optimizations
• Object Module Format
• Implementation-Defined Behavior
• Bit fields
D.4 POINTERS
D.13 PRAGMAS
The PIC18 MCU Compiler uses pragmas for sections (code, romdata, udata,
idata), interrupts (high-priority and low-priority) and variable locations (bank, section).
The 16-Bit Device Compiler uses non-ANSI attributes instead of pragmas.
Note: The 16-Bit Device Compiler does not directly support accessing variables
in program space. Variables so allocated must be explicitly accessed by the
programmer, usually using table-access inline assembly instructions, or
using the program space visibility window. See Section 4.14 “Program
Space Visibility (PSV) Usage” for more on the PSV window.
D.18 OPTIMIZATIONS
The following optimizations are part of each compiler.
MPLAB® C Compiler for
struct bar {
long long I:40;
char J:8;
int K:16;
} y;
struct foo will have a size of 10 bytes using the 16-Bit Device Compiler. i will be
allocated at bit offset 0 (through 39). There will be 8 bits of padding before j, allocated
at bit offset 48. If j were allocated at the next available bit offset, 40, it would cross a
storage boundary for a 16 bit integer. k will be allocated after j, at bit offset 64. The
structure will contain 8 bits of padding at the end to maintain the required alignment in
the case of an array. The alignment is 2 bytes because the largest alignment in the
structure is 2 bytes.
struct bar will have a size of 8 bytes using the 16-Bit Device Compiler. I will be allo-
cated at bit offset 0 (through 39). There is no need to pad before J because it will not
cross a storage boundary for a char. J is allocated at bit offset 40. K can be allocated
starting at bit offset 48, completing the structure without wasting any space.
E.2 HIGHLIGHTS
Deprecated features covered are:
• Predefined Constants
Hex 0 1 2 3 4 5 6 7
1 SOH DC1 ! 1 A Q a q
3 ETX DC3 # 3 C S c s
4 EOT DC4 $ 4 D T d t
5 ENQ NAK % 5 E U e u
9 HT EM ) 9 I Y i y
A LF SUB * : J Z j z
B VT ESC + ; K [ k {
C FF FS , < L \ l |
D CR GS - = M ] m }
E SO RS . > N ^ n ~
F SI US / ? O _ o DEL
G.1 PREAMBLE
The purpose of this License is to make a manual, textbook, or other functional and
useful document “free” in the sense of freedom: to assure everyone the effective
freedom to copy and redistribute it, with or without modifying it, either commercially or
non commercially. Secondarily, this License preserves for the author and publisher a
way to get credit for their work, while not being considered responsible for modifications
made by others.
This License is a kind of “copyleft”, which means that derivative works of the document
must themselves be free in the same sense. It complements the GNU General Public
License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because
free software needs free documentation: a free program should come with manuals
providing the same freedoms that the software does. But this License is not limited to
software manuals; it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License principally for
works whose purpose is instruction or reference.
G.5 MODIFICATIONS
You may copy and distribute a Modified Version of the Document under the conditions
of sections 2 and 3 above, provided that you release the Modified Version under
precisely this License, with the Modified Version filling the role of the Document, thus
licensing distribution and modification of the Modified Version to whoever possesses a
copy of it. In addition, you must do these things in the Modified Version:
a) Use in the Title Page (and on the covers, if any) a title distinct from that of the
Document, and from those of previous versions (which should, if there were any,
be listed in the History section of the Document). You may use the same title as
G.9 TRANSLATION
Translation is considered a kind of modification, so you may distribute translations of
the Document under the terms of section 4. Replacing Invariant Sections with transla-
tions requires special permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the original versions of these
Invariant Sections. You may include a translation of this License, and all the license
notices in the Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions of those notices
and disclaimers. In case of a disagreement between the translation and the original
version of this License or a notice or disclaimer, the original version will prevail.
If a section in the Document is Entitled “Acknowledgements”, “Dedications”, or
“History”, the requirement (section 4) to Preserve its Title (section 1) will typically
require changing the actual title.
G.10 TERMINATION
You may not copy, modify, sublicense, or distribute the Document except as expressly
provided for under this License. Any other attempt to copy, modify, sublicense or
distribute the Document is void, and will automatically terminate your rights under this
License. However, parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such parties remain in full
compliance.
Glossary
Access Memory (PIC18 Only)
Special registers on PIC18XXXXX devices that allow access regardless of the setting
of the Bank Select Register (BSR).
Address
Value that identifies a location in memory.
Alphabetic Character
Alphabetic characters are those characters that are letters of the arabic alphabet
(a, b, …, z, A, B, …, Z).
Alphanumeric
Alphanumeric characters are comprised of alphabetic characters and decimal digits
(0,1, …, 9).
Anonymous Structure
An unnamed structure.
ANSI
American National Standards Institute is an organization responsible for formulating
and approving standards in the United States.
Archive
A collection of relocatable object modules. It is created by assembling multiple source
files to object files, and then using the archiver to combine the object files into one
library file. A library can be linked with object modules and other libraries to create
executable code.
Archiver
A tool that creates and manipulates libraries.
ASCII
American Standard Code for Information Interchange is a character set encoding that
uses 7 binary digits to represent each character. It includes upper and lower case let-
ters, digits, symbols and control characters.
Assembler
A language tool that translates assembly language source code into machine code.
Assembly Language
A programming language that describes binary machine code in a symbolic form.
Attribute
Characteristics of variables or functions in a C program which are used to describe
machine-specific properties.
C
A general-purpose programming language which features economy of expression,
modern control flow and data structures and a rich set of operators.
Index
Symbols .dinit.......................................................................... 64
__builtin_add.......................................................... 142 .pbss......................................................................... 64
__builtin_addab...................................................... 142 .text .......................................................24, 36, 68, 135
__builtin_btg........................................................... 143 .tmpdata ................................................................. 207
__builtin_clr ............................................................ 143 #define ..................................................................... 52
__builtin_clr_prefect ............................................... 144 #ident ....................................................................... 57
__builtin_divf .......................................................... 145 #if ............................................................................. 45
__builtin_divmodsd ................................................ 145 #include ...................................................52, 53, 91, 93
__builtin_divmodud ................................................ 146 #line.......................................................................... 54
__builtin_divsd ....................................................... 146 #pragma ....................................................41, 135, 206
__builtin_divud ....................................................... 146 A
__builtin_dmaoffset ................................................ 147
-A.............................................................................. 51
__builtin_ed............................................................ 147
abort ................................................................. 24, 138
__builtin_edac ........................................................ 148
Access Memory...................................................... 205
__builtin_fbcl .......................................................... 148
address Attribute ................................................ 12, 20
__builtin_lac ........................................................... 149
Address Spaces ....................................................... 63
__builtin_mac ......................................................... 150
alias Attribute ........................................................... 20
__builtin_modsd ..................................................... 150
aligned Attribute ....................................................... 13
__builtin_modud..................................................... 151
Alignment ..............................................13, 15, 73, 134
__builtin_movsac ................................................... 151
-ansi ..............................................................26, 38, 54
__builtin_mpy ......................................................... 152
ANSI C Standard........................................................ 9
__builtin_mpyn ....................................................... 153
ANSI C, Differences with 16-Bit Device C................ 11
__builtin_msc ......................................................... 154
ANSI C, Strict ........................................................... 39
__builtin_mulss ...................................................... 154
ANSI Standard Library Support.................................. 9
__builtin_mulsu ...................................................... 155
ANSI-89 extension ................................................... 79
__builtin_mulus ...................................................... 155
Archiver ...................................................................... 8
__builtin_muluu ...................................................... 155
Arrays and Pointers................................................ 133
__builtin_nop.......................................................... 156
ASCII Character Set............................................... 213
__builtin_psvoffset ................................................. 156
asm ...........................................................13, 121, 205
__builtin_psvpage .................................................. 156
Assembler .................................................................. 8
__builtin_readsfr..................................................... 157
Assembly Options .................................................... 54
__builtin_return_address........................................ 157
-Wa ................................................................... 54
__builtin_sac .......................................................... 157
Assembly, Inline ............................................. 121, 205
__builtin_sacr ......................................................... 158
Assembly, Mixing with C ........................................ 119
__builtin_sftac ........................................................ 158
Atomic Operation ................................................... 114
__builtin_subab ...................................................... 159
attribute .......................................................12, 20, 206
__builtin_tbloffset ................................................... 159
Attribute, Function .................................................... 20
__builtin_tblpage .................................................... 159
address ............................................................. 20
__builtin_tblrdh....................................................... 160
alias................................................................... 20
__builtin_tblrdl ........................................................ 160
boot ................................................................... 21
__builtin_tblwth ...................................................... 161
const ................................................................. 22
__builtin_tblwtl........................................................ 161
deprecated ........................................................ 22
__builtin_write_NVM .............................................. 161
far ...................................................................... 22
__builtin_write_OSCCONH.................................... 162
format ................................................................ 22
__builtin_write_OSCCONL .................................... 162
format_arg......................................................... 23
__builtin_write_RTCWEN ...................................... 162
interrupt..............................................23, 101, 112
__C30_VERSION__ ................................................ 60
near ................................................................... 23
.bss....................................................................16, 135
no_instrument_function............................... 23, 57
.const...................................................................64, 76
noload ............................................................... 24
.data ..................................................................16, 135
noreturn....................................................... 24, 44
01/02/08