EW430 CompilerReference
EW430 CompilerReference
User Guide
C430-14
COPYRIGHT NOTICE
© 1996–2021 IAR Systems AB.
No part of this document may be reproduced without the prior written consent of IAR
Systems AB. The software described in this document is furnished under a license and
may only be used or copied in accordance with the terms of such a license.
DISCLAIMER
The information in this document is subject to change without notice and does not
represent a commitment on any part of IAR Systems. While the information contained
herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors
or omissions.
In no event shall IAR Systems, its employees, its contractors, or the authors of this
document be liable for special, direct, indirect, or consequential damage, losses, costs,
charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind.
TRADEMARKS
IAR Systems, IAR Embedded Workbench, Embedded Trust, C-Trust, IAR Connect,
C-SPY, C-RUN, C-STAT, IAR Visual State, IAR KickStart Kit, I-jet, I-jet Trace,
I-scope, IAR Academy, IAR, and the logotype of IAR Systems are trademarks or
registered trademarks owned by IAR Systems AB.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
Texas Instruments is a registered trademark of Texas Instruments Corporation. MSP430
is a trademark of Texas Instruments Corporation.
Adobe and Acrobat Reader are registered trademarks of Adobe Systems Incorporated.
All other product names are trademarks or registered trademarks of their respective
owners.
EDITION NOTICE
Fourteenth edition: March 2021
Part number: C430-14
This guide applies to version 7.x of IAR Embedded Workbench® for the Texas
Instruments MSP430 microcontroller family.
Internal reference: M23, Mym8.5, docsrc-6.10, V_140324, INIT
AFE1_AFE2-1:1
Brief contents
Tables ..................................................................................................................... 27
Preface .................................................................................................................... 29
Functions ............................................................................................................... 71
AFE1_AFE2-1:1
Pragma directives ........................................................................................... 331
AFE1_AFE2-1:1
Contents
Tables ..................................................................................................................... 27
Preface .................................................................................................................... 29
Who should read this guide ............................................................... 29
Required knowledge .......................................................................... 29
How to use this guide .......................................................................... 29
What this guide contains ................................................................... 30
Part 1. Using the compiler .................................................................. 30
Part 2. Reference information ............................................................ 31
Other documentation ........................................................................... 31
User and reference guides .................................................................. 32
The online help system ...................................................................... 32
Further reading ................................................................................... 33
Web sites ............................................................................................ 33
Document conventions ........................................................................ 33
Typographic conventions ................................................................... 34
Naming conventions .......................................................................... 35
AFE1_AFE2-1:1
Special support for embedded systems ........................................ 42
Extended keywords ............................................................................ 42
Pragma directives ............................................................................... 43
Predefined symbols ............................................................................ 43
Accessing low-level features ............................................................. 43
Introduction ............................................................................................. 59
Different ways to store data ............................................................... 60
AFE1_AFE2-1:1
Contents
Functions ............................................................................................................... 71
AFE1_AFE2-1:1
Linking overview ............................................................................................. 85
AFE1_AFE2-1:1
Contents
AFE1_AFE2-1:1
__open .............................................................................................. 142
raise .................................................................................................. 143
__read .............................................................................................. 143
remove .............................................................................................. 144
rename .............................................................................................. 145
__ReportAssert ................................................................................ 145
signal ................................................................................................ 145
system ............................................................................................... 146
__time32, __time64 ......................................................................... 146
__write ............................................................................................. 146
Configuration symbols for printf and scanf ..................................... 148
Configuration symbols for file input and output .............................. 149
Locale ............................................................................................... 149
Strtod ................................................................................................ 151
Hardware multiplier support ............................................................ 151
MPU/IPE support ............................................................................. 152
Managing a multithreaded environment .................................... 154
Multithread support in the DLIB runtime environment ................... 154
Enabling multithread support ........................................................... 155
TLS in the linker configuration file ................................................. 160
AFE1_AFE2-1:1
Contents
11
AFE1_AFE2-1:1
Memory access methods ................................................................... 191
The data16 memory access method ................................................. 192
The data20 memory access method ................................................. 192
Call frame information ....................................................................... 193
CFI directives ................................................................................... 193
Creating assembler source with CFI support ................................... 194
AFE1_AFE2-1:1
Contents
13
AFE1_AFE2-1:1
Protecting simultaneously accessed variables .................................. 248
Accessing special function registers ................................................ 249
Non-initialized variables .................................................................. 251
Efficient switch statements .............................................................. 252
AFE1_AFE2-1:1
Contents
15
AFE1_AFE2-1:1
--no_cse ............................................................................................ 286
--no_inline ........................................................................................ 287
--no_path_in_file_macros ................................................................ 287
--no_rw_dynamic_init ...................................................................... 287
--no_size_constraints ....................................................................... 288
--no_static_destruction ..................................................................... 288
--no_system_include ........................................................................ 288
--no_tbaa .......................................................................................... 289
--no_typedefs_in_diagnostics .......................................................... 289
--no_ubrof_messages ....................................................................... 290
--no_unroll ....................................................................................... 290
--no_warnings .................................................................................. 290
--no_wrap_diagnostics ..................................................................... 290
-O ..................................................................................................... 291
--omit_types ..................................................................................... 291
--only_stdout .................................................................................... 292
--output, -o ....................................................................................... 292
--pending_instantiations ................................................................... 292
--predef_macros ............................................................................... 293
--preinclude ..................................................................................... 293
--preprocess ...................................................................................... 293
--public_equ ..................................................................................... 294
--reduce_stack_usage ....................................................................... 294
--regvar_r4 ....................................................................................... 294
--regvar_r5 ....................................................................................... 295
--relaxed_fp ...................................................................................... 295
--remarks .......................................................................................... 296
--require_prototypes ......................................................................... 296
--ropi ................................................................................................. 296
--save_reg20 ..................................................................................... 297
--segment .......................................................................................... 297
--silent .............................................................................................. 299
--strict ............................................................................................... 299
--system_include_dir ........................................................................ 299
AFE1_AFE2-1:1
Contents
17
AFE1_AFE2-1:1
Declaring objects const .................................................................... 315
Data types in C++ ................................................................................. 315
Extended keywords ...................................................................................... 317
AFE1_AFE2-1:1
Contents
19
AFE1_AFE2-1:1
segment ............................................................................................ 350
STDC CX_LIMITED_RANGE ....................................................... 351
STDC FENV_ACCESS ................................................................... 352
STDC FP_CONTRACT .................................................................. 352
type_attribute ................................................................................... 352
unroll ................................................................................................ 353
vector ................................................................................................ 354
weak ................................................................................................. 354
AFE1_AFE2-1:1
Contents
21
AFE1_AFE2-1:1
__PRETTY_FUNCTION__ ............................................................ 373
__REGISTER_MODEL__ .............................................................. 373
__REGISTER_R4__ ....................................................................... 373
__REGISTER_R5__ ....................................................................... 373
__ROPI__ ........................................................................................ 373
__STDC__ ....................................................................................... 373
__STDC_VERSION__ ................................................................... 374
__SUBVERSION__ ........................................................................ 374
__TIME__ ....................................................................................... 374
__TIMESTAMP__ .......................................................................... 374
__VER__ ......................................................................................... 374
Descriptions of miscellaneous preprocessor extensions ..... 374
NDEBUG ........................................................................................ 375
#warning message ........................................................................... 375
AFE1_AFE2-1:1
Contents
23
AFE1_AFE2-1:1
IPE_B2 ............................................................................................. 400
IPECODE16 ..................................................................................... 400
IPEDATA16_C ................................................................................ 401
IPEDATA16_N ................................................................................ 401
IPESIGNATURE ............................................................................. 401
ISR_CODE ....................................................................................... 401
JTAGSIGNATURE ......................................................................... 402
MPU_B1 .......................................................................................... 402
MPU_B2 .......................................................................................... 402
REGVAR_AN ................................................................................. 402
RESET ............................................................................................. 403
SIGNATURE ................................................................................... 403
TLS16_I ........................................................................................... 403
TLS16_ID ........................................................................................ 404
AFE1_AFE2-1:1
Contents
25
AFE1_AFE2-1:1
Index ..................................................................................................................... 443
AFE1_AFE2-1:1
Tables
1: Typographic conventions used in this guide ......................................................... 34
2: Naming conventions used in this guide ................................................................ 35
3: Memory types and their corresponding memory attributes .................................. 61
4: Data model characteristics .................................................................................... 66
5: Heaps supported in memory types ........................................................................ 70
6: Code models .......................................................................................................... 72
7: segments holding initialized data .......................................................................... 90
8: Example of runtime model attributes .................................................................. 112
9: Predefined runtime model attributes ................................................................... 113
10: Debug information and levels of C-SPY emulated I/O .................................... 120
11: Library configurations ....................................................................................... 127
12: Formatters for printf .......................................................................................... 129
13: Formatters for scanf .......................................................................................... 130
14: Extended command line files for the small math functions .............................. 132
15: DLIB low-level I/O interface functions ............................................................ 139
16: Descriptions of printf configuration symbols ................................................... 148
17: Descriptions of scanf configuration symbols .................................................... 148
18: Additional linker configuration files for the hardware multiplier ..................... 152
19: Library objects using TLS ................................................................................. 155
20: Macros for implementing TLS allocation ......................................................... 158
21: Inline assembler operand constraints ................................................................ 174
22: Supported constraint modifiers ......................................................................... 174
23: List of valid clobbers ......................................................................................... 176
24: Operand modifiers and transformations ............................................................ 177
25: Registers used for passing parameters .............................................................. 186
26: Registers used for returning values ................................................................... 187
27: Call frame information resources defined in a names block ............................. 193
28: Language extensions ......................................................................................... 199
29: Compiler optimization levels ............................................................................ 242
30: Compiler environment variables ....................................................................... 256
31: Error return codes .............................................................................................. 259
27
AFE1_AFE2-1:1
32: Compiler options summary ............................................................................... 265
33: Integer types ...................................................................................................... 304
34: Floating-point types .......................................................................................... 307
35: Function pointers ............................................................................................... 309
36: Data pointers ..................................................................................................... 309
37: Extended keywords summary ........................................................................... 320
38: Pragma directives summary .............................................................................. 331
39: Intrinsic functions summary .............................................................................. 355
40: Functions for binary coded decimal operations ................................................ 357
41: Functions for reading data that has a 20-bit address ......................................... 360
42: Functions for writing data that has a 20-bit address ......................................... 361
43: Traditional Standard C header files—DLIB ..................................................... 380
44: C++ header files ................................................................................................ 381
45: Standard template library header files ............................................................... 382
46: New Standard C header files—DLIB ............................................................... 382
47: CLIB runtime environment header files ........................................................... 386
48: Segment summary ............................................................................................. 387
49: Message returned by strerror()—DLIB runtime environment .......................... 428
50: Message returned by strerror()—DLIB runtime environment .......................... 439
51: Message returned by strerror()—CLIB runtime environment .......................... 442
AFE1_AFE2-1:1
Preface
Welcome to the IAR C/C++ Compiler User Guide for MSP430. The purpose of
this guide is to provide you with detailed reference information that can help
you to use the compiler to best suit your application requirements. This guide
also gives you suggestions on coding techniques so that you can develop
applications with maximum efficiency.
REQUIRED KNOWLEDGE
To use the tools in IAR Embedded Workbench, you should have working knowledge of:
● The architecture and instruction set of the MSP430 microcontroller (refer to the
chip manufacturer's documentation)
● The C or C++ programming language
● Application development for embedded systems
● The operating system of your host computer.
For more information about the other development tools incorporated in the IDE, refer
to their respective documentation, see Other documentation, page 31.
29
AFE1_AFE2-1:1
What this guide contains
AFE1_AFE2-1:1
Preface
Other documentation
User documentation is available as hypertext PDFs and as a context-sensitive online
help system in HTML format. You can access the documentation from the Information
Center or from the Help menu in the IAR Embedded Workbench IDE. The online help
system is also available via the F1 key.
31
AFE1_AFE2-1:1
Other documentation
AFE1_AFE2-1:1
Preface
using the CLIB C standard library, you will get reference information for the DLIB
C standard library.
FURTHER READING
These books might be of interest to you when using the IAR Systems development tools:
● Barr, Michael, and Andy Oram, ed. Programming Embedded Systems in C and
C++. O’Reilly & Associates.
● Harbison, Samuel P. and Guy L. Steele (contributor). C: A Reference Manual.
Prentice Hall.
● Labrosse, Jean J. Embedded Systems Building Blocks: Complete and Ready-To-Use
Modules in C. R&D Books.
● Mann, Bernhard. C für Mikrocontroller. Franzis-Verlag. [Written in German.]
● Meyers, Scott. Effective C++. Addison-Wesley.
● Meyers, Scott. More Effective C++. Addison-Wesley.
● Meyers, Scott. Effective STL. Addison-Wesley.
● Sutter, Herb. Exceptional C++: 47 Engineering Puzzles, Programming Problems,
and Solutions. Addison-Wesley.
The web site isocpp.org also has a list of recommended books about C++ programming.
WEB SITES
Recommended web sites:
● The Texas Instruments web site, www.ti.com, that contains information and news
about the MSP430 microcontrollers.
● The IAR Systems web site, www.iar.com, that holds application notes and other
product information.
● The web site of the C standardization working group,
www.open-std.org/jtc1/sc22/wg14.
● The web site of the C++ Standards Committee, www.open-std.org/jtc1/sc22/wg21.
● The C++ programming language web site, isocpp.org. This web site also has a list
of recommended books about C++ programming.
● The C and C++ reference web site, en.cppreference.com.
Document conventions
When, in the IAR Systems documentation, we refer to the programming language C, the
text also applies to C++, unless otherwise stated.
33
AFE1_AFE2-1:1
Document conventions
When referring to a directory in your product installation, for example 430\doc, the full
path to the location is assumed, for example c:\Program Files\IAR
Systems\Embedded Workbench N.n\430\doc, where the initial digit of the version
number reflects the initial digit of the version number of the IAR Embedded Workbench
shared components.
TYPOGRAPHIC CONVENTIONS
The IAR Systems documentation set uses the following typographic conventions:
Style Used for
computer • Source code examples and file paths.
• Text on the command line.
• Binary, hexadecimal, and octal numbers.
parameter A placeholder for an actual value used as a parameter, for example
filename.h where filename represents the name of the file.
[option] An optional part of a stack usage control directive, where [ and ] are
not part of the actual directive, but any [, ], {, or } are part of the
directive syntax.
{option} A mandatory part of a stack usage control directive, where { and } are
not part of the actual directive, but any [, ], {, or } are part of the
directive syntax.
[option] An optional part of a command line option, pragma directive, or library
filename.
[a|b|c] An optional part of a command line option, pragma directive, or library
filename with alternatives.
{a|b|c} A mandatory part of a command line option, pragma directive, or
library filename with alternatives.
bold Names of menus, menu commands, buttons, and dialog boxes that
appear on the screen.
italic • A cross-reference within this guide or to another guide.
• Emphasis.
… An ellipsis indicates that the previous item can be repeated an arbitrary
number of times.
Identifies instructions specific to the IAR Embedded Workbench® IDE
interface.
Identifies instructions specific to the command line interface.
Identifies helpful tips and programming hints.
AFE1_AFE2-1:1
Preface
NAMING CONVENTIONS
The following naming conventions are used for the products and tools from IAR
Systems®, when referred to in the documentation:
Brand name Generic term
IAR Embedded Workbench® for MSP430 IAR Embedded Workbench®
IAR Embedded Workbench® IDE for MSP430 the IDE
IAR C-SPY® Debugger for MSP430 C-SPY, the debugger
IAR C-SPY® Simulator the simulator
IAR C/C++ Compiler™ for MSP430 the compiler
IAR Assembler™ for MSP430 the assembler
IAR XLINK Linker™ XLINK, the linker
IAR XAR Library Builder™ the library builder
IAR XLIB Librarian™ the librarian
IAR CLIB Runtime Environment™ the CLIB runtime environment
IAR DLIB Runtime Environment™ the DLIB runtime environment
Table 2: Naming conventions used in this guide
35
AFE1_AFE2-1:1
Document conventions
AFE1_AFE2-1:1
Part 1. Using the compiler
This part of the IAR C/C++ Compiler User Guide for MSP430 includes these
chapters:
● Data storage
● Functions
● Linking overview
● Using C
● Using C++
● Application-related considerations
37
38
Introduction to the IAR
build tools
● The IAR build tools—an overview
● Device support
39
AFE1_AFE2-1:1
IAR language overview
The IAR Assembler for MSP430 uses the same mnemonics and operand syntax as the
Texas Instruments MSP430 Assembler, which simplifies the migration of existing code.
For more information, see the IAR Assembler User Guide for MSP430.
EXTERNAL TOOLS
For information about how to extend the tool chain in the IDE, see the IDE Project
Management and Building Guide.
AFE1_AFE2-1:1
Introduction to the IAR build tools
For more information about Embedded C++ and Extended Embedded C++, see the
chapter Using C++.
For information about how the compiler handles the implementation-defined areas of
the languages, see the chapter Implementation-defined behavior for Standard C.
It is also possible to implement parts of the application, or the whole application, in
assembler language. See the IAR Assembler User Guide for MSP430.
Device support
To get a smooth start with your product development, the IAR product installation
comes with a wide range of device-specific support.
41
AFE1_AFE2-1:1
Special support for embedded systems
EXTENDED KEYWORDS
The compiler provides a set of keywords that can be used for configuring how the code
is generated. For example, there are keywords for controlling how to access and store
data objects, as well as for controlling how a function should work internally and how
it should be called/returned.
AFE1_AFE2-1:1
Introduction to the IAR build tools
PRAGMA DIRECTIVES
The pragma directives control the behavior of the compiler, for example how it allocates
memory, whether it allows extended keywords, and whether it issues warning messages.
The pragma directives are always enabled in the compiler. They are consistent with
standard C, and are useful when you want to make sure that the source code is portable.
For more information about the pragma directives, see the chapter Pragma directives.
PREDEFINED SYMBOLS
With the predefined preprocessor symbols, you can inspect your compile-time
environment, for example time of compilation or the build number of the compiler.
For more information about the predefined symbols, see the chapter The preprocessor.
43
AFE1_AFE2-1:1
Special support for embedded systems
AFE1_AFE2-1:1
Developing embedded
applications
● Developing embedded software using IAR build tools
MAPPING OF MEMORY
Embedded systems typically contain various types of memory, such as RAM, FRAM,
ROM, EEPROM, or flash memory.
As an embedded software developer, you must understand the features of the different
types of memory. For example, on-chip RAM is often faster than other types of
memories, and variables that are accessed often would in time-critical applications
45
AFE1_AFE2-1:1
Developing embedded software using IAR build tools
benefit from being placed here. Conversely, some configuration data might be seldom
accessed but must maintain its value after power off, so it should be saved in EEPROM
or flash memory.
For efficient memory usage, the compiler provides several mechanisms for controlling
placement of functions and data objects in memory. For more information, see
Controlling data and function placement in memory, page 236.
The linker places sections of code and data in memory according to the directives you
specify in the linker configuration file, see Placing code and data—the linker
configuration file, page 88.
EVENT HANDLING
In embedded systems, using interrupts is a method for handling external events
immediately, for example, detecting that a button was pressed. In general, when an
interrupt occurs in the code, the microcontroller immediately stops executing the code
it runs, and starts executing an interrupt routine instead.
The compiler provides various primitives for managing hardware and software
interrupts, which means that you can write your interrupt routines in C, see Primitives
for interrupts, concurrency, and OS-related programming, page 73.
SYSTEM STARTUP
In all embedded systems, system startup code is executed to initialize the system—both
the hardware and the software system—before the main function of the application is
called.
As an embedded software developer, you must ensure that the startup code is located at
the dedicated memory addresses, or can be accessed using a pointer from the vector
table. This means that startup code and the initial vector table must be placed in
non-volatile memory, such as ROM, EPROM, or flash.
AFE1_AFE2-1:1
Developing embedded applications
A C/C++ application further needs to initialize all global variables. This initialization is
handled by the linker in conjunction with the system startup code. For more information,
see Application execution—an overview, page 50.
47
AFE1_AFE2-1:1
The build process—an overview
After the translation, you can choose to pack any number of modules into an archive, or
in other words, a library. The important reason you should use libraries is that each
module in a library is conditionally linked in the application, or in other words, is only
included in the application if the module is used directly or indirectly by a module
supplied as an object file. Optionally, you can create a library, then use the IAR XAR
Library Builder or the IAR XLIB Librarian.
AFE1_AFE2-1:1
Developing embedded applications
The IAR XLINK Linker produces output according to your specifications. Choose
the output format that suits your purpose. You might want to load the output to a
debugger—which means that you need output with debug information. Alternatively,
you might want to load output to a flash loader or a PROM programmer—in which
case you need output without debug information, such as Intel hex or Motorola S–
records. The option -F can be used for specifying the output format.
This illustration shows the linking process:
Note: The Standard C/C++ library contains support routines for the compiler, and the
implementation of the C/C++ standard library functions.
While linking, the linker might produce error messages and logging messages on
stdout and stderr. The log messages are useful for understanding why an application
was linked the way it was, for example, why a module was included or a section
removed.
For more information about the procedure performed by the linker, see the IAR Linker
and Library Tools Reference Guide.
49
AFE1_AFE2-1:1
Application execution—an overview
AFTER LINKING
The IAR XLINK Linker produces an absolute object file in the output format you
specify. After linking, the produced absolute executable image can be used for:
● Loading into the IAR C-SPY Debugger or any other compatible external debugger
that reads UBROF.
● Programming to a flash/PROM using a flash/PROM programmer.
This illustration shows the possible uses of the absolute output files:
AFE1_AFE2-1:1
Developing embedded applications
51
AFE1_AFE2-1:1
Application execution—an overview
2 Then, memories that should be zero-initialized are cleared, in other words, filled with
zeros:
AFE1_AFE2-1:1
Developing embedded applications
For more information about each stage, see System startup and termination, page 135.
For more information about initialization of data, see Initialization at system startup,
page 89.
53
AFE1_AFE2-1:1
Building applications—an overview
You must also specify some critical options, see Basic project configuration, page 54.
On the command line, the following line can be used for starting the linker:
xlink myfile.r43 myfile2.r43 -o a.d43 -f my_configfile.xcl -r
AFE1_AFE2-1:1
Developing embedded applications
● Optimization settings
● Runtime environment, see Setting up the runtime environment, page 119
● Position-independent code and read-only data
● Customizing the XLINK configuration, see the chapter Linking your application.
In addition to these settings, you can use many other options and settings to fine-tune
the result even further. For information about how to set options and for a list of all
available options, see the chapter Compiler options and the IDE Project Management
and Building Guide, respectively.
PROCESSOR CONFIGURATION
To make the compiler generate optimum code, you should configure it for the MSP430
microcontroller you are using.
Core
The compiler supports both the MSP430 architecture that has 64 Kbytes of addressable
memory and the MSP430X architecture that has the extended instruction set and 1
Mbyte of addressable memory.
Use the --core={430|430X} option to select the architecture for which the code will
be generated.
In the IDE, choose Project>Options>General Options>Target and choose an
appropriate device from the Device drop-down list. The core option will then be
automatically selected.
Note: Device-specific configuration files for the linker and the debugger will also be
automatically selected.
Hardware multiplier
Some MSP430 devices contain a hardware multiplier. The IAR C/C++ Compiler for
MSP430 can generate code that accesses this unit. In addition, the runtime library
contains hardware multiplier-aware modules that can be used instead of the normal
arithmetical routines.
To direct the compiler to take advantage of the unit, choose Project>Options>General
Options>Target and choose a device from the Device drop-down menu that contains a
hardware multiplier unit.
To use the hardware multiplier, enable it on the command line using the --multiplier
(and in some cases also the--multiplier_location) option. You must also, in
55
AFE1_AFE2-1:1
Basic project configuration
addition to the runtime library object file, extend the linker command line with one of
these configuration files:
-f multiplier.xcl
-f multiplier32.xcl
AFE1_AFE2-1:1
Developing embedded applications
Note: The call and return sequences are different if --ropi is used.
For more information about the code models, see the chapter Functions.
57
AFE1_AFE2-1:1
Basic project configuration
AFE1_AFE2-1:1
Data storage
● Introduction
● Data models
Introduction
The compiler supports MSP430 devices with both the MSP430 instruction set and the
MSP430X extended instruction set, which means that 64 Kbytes and 1 Mbyte of
continuous memory can be used, respectively.
Different types of physical memory can be placed in the memory range. A typical
application will have both read-only memory (ROM or flash) and read/write memory
(RAM). In addition, some parts of the memory range contain processor control registers
and peripheral units.
Some devices support FRAM, a memory type that can be written to like RAM, but
retains its contents after a power-down like traditional read-only memories. FRAM can
be partitioned to contain read-only segments and read/write segments.
The MSP430X architecture can access the lower 64 Kbyte using normal instructions and
the entire memory range using more expensive extended instructions. The compiler
supports this by means of memory types, where data16 memory corresponds to the
lower 64 Kbytes and the data20 memory the entire 1 Mbyte memory range. For more
information about this, see Memory types (MSP430X only), page 60.
Placing read-only (constant) data in data20 memory is useful for most MSP430X
devices. However, using data20 memory for read/write data only makes sense if the
device has RAM or FRAM memory above the first 64 Kbytes.
59
AFE1_AFE2-1:1
Memory types (MSP430X only)
AFE1_AFE2-1:1
Data storage
amount of data, and at the same time make sure that variables that are used often are
placed in memory that can be efficiently accessed.
Below is an overview of the memory types.
Data16
The data16 memory consists of the low 64 Kbytes of data memory. In hexadecimal
notation, this is the address range 0x0000-0xFFFF.
A pointer to data16 memory is 16 bits and occupies two bytes when stored in memory.
Direct accesses to data16 memory are performed using normal (non-extended)
instructions. This means a smaller footprint for the application, and faster execution at
runtime.
Data20
Using the data20 memory type, you can place the data objects anywhere in the entire
memory range 0x00000–0xFFFFF. This requires the extended instructions of the
MSP430X architecture, which are more expensive. Note that a pointer to data20
memory will occupy four bytes of memory, which is twice the amount needed for data16
memory.
Note: Data20 is not available in the Small data model.
Default in
Memory type Keyword Address range Pointer size
data model
Data16 __data16 0x0-0xFFFF 16 bits Small and
Medium
Data20 __data20 0x0-0xFFFFF 32 bits Large
Table 3: Memory types and their corresponding memory attributes
The keywords are only available if language extensions are enabled in the compiler.
In the IDE, language extensions are enabled by default.
61
AFE1_AFE2-1:1
Memory types (MSP430X only)
Use the -e compiler option to enable language extensions. See -e, page 278 for
additional information.
For more information about each keyword, see Descriptions of extended keywords, page
321.
__data16 int i;
int __data16 j;
In all cases, if a memory attribute is not specified, an appropriate default memory type
is used, which depends on the data model in use.
Using a type definition can sometimes make the code clearer:
typedef __data16 int d16_int;
d16_int *q1;
d16_int is a typedef for integers in data16 memory. The variable q1 can point to such
integers.
You can also use the #pragma type_attributes directive to specify type attributes
for a declaration. The type attributes specified in the pragma directive are applied to the
data object or typedef being declared.
#pragma type_attribute=__data16
int * q2;
AFE1_AFE2-1:1
Data storage
Type definitions
Storage can also be specified using type definitions. These two declarations are
equivalent:
/* Defines via a typedef */
typedef char __data20 D20Byte;
typedef D20Byte *D20BytePtr;
D20Byte aByte;
D20BytePtr aBytePointer;
/* Defines directly */
__data20 char aByte;
char __data20 *aBytePointer;
Note that the location of the pointer variable myPtr is not affected by the keyword. In
the following example, however, the pointer variable myPtr2 is placed in data20
memory. Like myPtr, myPtr2 points to a character in data16 memory.
char __data16 * __data20 myPtr2;
For example, the functions in the standard library are all declared without explicit
memory types.
63
AFE1_AFE2-1:1
Memory types (MSP430X only)
MORE EXAMPLES
The following is a series of examples with descriptions. First, some integer variables are
defined and then pointer variables are introduced. Finally, a function accepting a pointer
to an integer in data16 memory is declared. The function returns a pointer to an integer
AFE1_AFE2-1:1
Data storage
in data20 memory. It makes no difference whether the memory attribute is placed before
or after the data type.
65
AFE1_AFE2-1:1
Data models
Data models
Data models are only available for the MSP430X architecture.
Use data models to specify in which part of memory the compiler should place static
and global variables by default. This means that the data model controls:
● The default memory type
● The default placement of static and global variables, and constant literals
● The placement of dynamically allocated data, for example data allocated with
malloc, or, in C++, the operator new
● The default pointer type
The data model specifies the default memory type. In the Small data model, only the
data16 memory type is available. In the Medium and Large data models, you can
explicitly override the default memory type for individual variables and pointers. For
information about how to specify a memory type for individual objects, see Using data
memory attributes, page 61.
Note: Your choice of data model does not affect the placement of code.
See the IDE Project Management and Building Guide for information about setting
options in the IDE.
AFE1_AFE2-1:1
Data storage
Use the --data_model option to specify the data model for your project; see
--data_model, page 272.
67
AFE1_AFE2-1:1
Storage of auto variables and parameters
THE STACK
The stack can contain:
● Local variables and parameters not stored in registers
● Temporary results of expressions
● The return value of a function (unless it is passed in registers)
● Processor state during interrupts
● Processor registers that should be restored before the function returns (callee-save
registers).
The stack is a fixed block of memory, divided into two parts. The first part contains
allocated memory used by the function that called the current function, and the function
that called it, etc. The second part contains free memory that can be allocated. The
borderline between the two areas is called the top of stack and is represented by the stack
pointer, which is a dedicated processor register. Memory is allocated on the stack by
moving the stack pointer.
AFE1_AFE2-1:1
Data storage
A function should never refer to the memory in the area of the stack that contains free
memory. The reason is that if an interrupt occurs, the called interrupt function can
allocate, modify, and—of course—deallocate memory on the stack.
See also Stack considerations, page 221 and Setting up stack memory, page 105.
Advantages
The main advantage of the stack is that functions in different parts of the program can
use the same memory space to store their data. Unlike a heap, a stack will never become
fragmented or suffer from memory leaks.
It is possible for a function to call itself either directly or indirectly—a recursive
function—and each invocation can store its own data on the stack.
Potential problems
The way the stack works makes it impossible to store data that is supposed to live after
the function returns. The following function demonstrates a common programming
mistake. It returns a pointer to the variable x, a variable that ceases to exist when the
function returns.
int *MyFunction()
{
int x;
/* Do something here. */
return &x; /* Incorrect */
}
Another problem is the risk of running out of stack space. This will happen when one
function calls another, which in turn calls a third, etc., and the sum of the stack usage of
each function is larger than the size of the stack. The risk is higher if large data objects
are stored on the stack, or when recursive functions are used.
69
AFE1_AFE2-1:1
Dynamic memory on the heap
Used by default in
Memory type Memory attribute Section name
data model
data16 __data16 DATA16_HEAP Small and Medium
data20 __data20 DATA20_HEAP Large
Table 5: Heaps supported in memory types
In DLIB, to use a specific heap, add the memory attribute in front of malloc, free,
alloc, and realloc, for example __data16_malloc. The default functions will use
of the specific heap variants, depending on project settings such as data model.
For information about how to set up the size for heap memory, see Setting up heap
memory, page 106.
POTENTIAL PROBLEMS
Applications that use heap-allocated data objects must be carefully designed, as it is
easy to end up in a situation where it is not possible to allocate objects on the heap.
The heap can become exhausted if your application uses too much memory. It can also
become full if memory that no longer is in use was not released.
For each allocated memory block, a few bytes of data for administrative purposes is
required. For applications that allocate a large number of small blocks, this
administrative overhead can be substantial.
There is also the matter of fragmentation; this means a heap where small sections of free
memory is separated by memory used by allocated objects. It is not possible to allocate
a new object if no piece of free memory is large enough for the object, even though the
sum of the sizes of the free memory exceeds the size of the object.
Unfortunately, fragmentation tends to increase as memory is allocated and released. For
this reason, applications that are designed to run for a long time should try to avoid using
memory allocated on the heap.
AFE1_AFE2-1:1
Functions
● Function-related extensions
● Execution in RAM
● Inlining functions
Function-related extensions
In addition to supporting Standard C, the compiler provides several extensions for
writing functions in C. Using these, you can:
● Control call and return sequences
● Execute functions in RAM
● Use primitives for interrupts, concurrency, and OS-related programming
● Control function inlining
● Facilitate function optimization
● Access hardware features.
The compiler uses compiler options, extended keywords, pragma directives, and
intrinsic functions to support this.
For more information about optimizations, see Efficient coding for embedded
applications, page 233. For information about the available intrinsic functions for
accessing hardware operations, see the chapter Intrinsic functions.
71
AFE1_AFE2-1:1
Code models (MSP430X only)
If you do not specify a code model, the compiler will use the Large code model as
default.
See the IDE Project Management and Building Guide for information about specifying
a code model in the IDE.
Use the --code_model option to specify the code model for your project; see
--code_model, page 270.
AFE1_AFE2-1:1
Functions
INTERRUPT FUNCTIONS
In embedded systems, using interrupts is a method for handling external events
immediately; for example, detecting that a button was pressed.
73
AFE1_AFE2-1:1
Primitives for interrupts, concurrency, and OS-related programming
Note: An interrupt function must have the return type void, and it cannot specify any
parameters.
This creates an interrupt service routine where you must make sure that the code within
the routine does not affect any of the registers used by the interrupted environment.
Typically, this is useful for applications that have an empty foreground loop and use
interrupt routines to perform all work.
Note: The same effect can be achieved for normal functions by using the __task
keyword.
AFE1_AFE2-1:1
Functions
The interrupt vector register contains information about the interrupt source, and the
interrupt service routine normally uses a switch statement to find out which interrupt
source issued the interrupt. To help the compiler generate optimal code for the switch
statement, the intrinsic function __even_in_range can be used. This example defines
a Timer A interrupt routine:
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
switch (__even_in_range(TAIV, 10))
{
case 2: P1POUT ˆ= 0x04;
break;
case 4: P1POUT ˆ= 0x02;
break;
case 10: P1POUT ˆ= 0x01;
break;
}
}
The intrinsic function __even_in_range requires two parameters, the interrupt vector
register and the last value in the allowed range, which in this example is 10. The effect
of the intrinsic function is that the generated code can only handle even values within
the given range, which is exactly what is required in this case as the interrupt vector
register for Timer A can only be 0, 2, 4, 6, 8, or 10.
If the __even_in_range intrinsic function is applied to any other value, the effect is
undefined and the application will most likely fail.
For more information about the intrinsic keyword, see __even_in_range, page 362.
75
AFE1_AFE2-1:1
Primitives for interrupts, concurrency, and OS-related programming
not lock R4/R5, the upper four bits of R4/R5 might be destroyed. For this reason, it is not
recommended to use different settings of the --lock_R4/R5 option for different
modules.
MONITOR FUNCTIONS
A monitor function causes interrupts to be disabled during execution of the function. At
function entry, the status register is saved and interrupts are disabled. At function exit,
the original status register is restored, and thereby the interrupt status that existed before
the function call is also restored.
To define a monitor function, you can use the __monitor keyword. For more
information, see __monitor, page 324.
Avoid using the __monitor keyword on large functions, since the interrupt will
otherwise be turned off for a significant period of time.
AFE1_AFE2-1:1
Functions
sTheLock = 1;
return 1;
}
else
{
/* Failure, someone else has the lock. */
return 0;
}
}
void GetLock(void)
{
while (!TryGetLock())
{
/* Normally, a sleep instruction is used here. */
}
}
77
AFE1_AFE2-1:1
Primitives for interrupts, concurrency, and OS-related programming
void MyProgram(void)
{
GetLock();
/* Do something here. */
ReleaseLock();
}
~Mutex()
{
// Restore the interrupt state.
__set_interrupt_state(mState);
}
AFE1_AFE2-1:1
Functions
private:
__istate_t mState;
};
class Tick
{
public:
// Function to read the tick count safely.
static long GetTick()
{
long t;
private:
static volatile long smTickCount;
};
void MyMain()
{
static long nextStop = 100;
Execution in RAM
The __ramfunc keyword makes a function execute in RAM. The function is copied
from ROM to RAM by cstartup, see System startup and termination, page 135.
79
AFE1_AFE2-1:1
Position-independent code and read-only data
If the whole memory area used for code and constants is disabled—for example, when
the whole flash memory is being erased—only functions and data stored in RAM can be
used. Interrupts must be disabled unless the interrupt vector and the interrupt service
routines are also stored in RAM.
AFE1_AFE2-1:1
Functions
Note: In some cases, there is an alternative to ROPI that avoids these limitations and
drawbacks: If there is only a small number of possible placements for the application,
you can compile the application without --ropi and link it multiple times, once for
each possible placement. Then you can choose the correct image at load time. When
applicable, this approach makes better use of the available hardware resources than
using ROPI.
INITIALIZATION OF POINTERS
In a ROPI application, the actual addresses of read-only data variables are only known
at runtime. A pointer to data always holds the actual address, so that it can be used
efficiently in indirect and indexed addressing modes. This means that pointers to
read-only data cannot be initialized statically (by copying from ROM at startup). For
non-constant global and static pointer variables, the compiler automatically rewrites
static initializations to dynamic ones, where the actual address is computed at program
startup. This rewriting can be disabled if you prefer the compiler to issue an error
message at compile-time, see --no_rw_dynamic_init, page 287.
Unlike data pointers, function pointers in a ROPI application hold the linked address of
a function, and the actual address is only computed when the function is called. This
means that function pointers work as usual without limitations.
Inlining functions
Function inlining means that a function, whose definition is known at compile time, is
integrated into the body of its caller to eliminate the overhead of the function call. This
optimization, which is performed at optimization level High, normally reduces
execution time, but might increase the code size. The resulting code might become more
difficult to debug. Whether the inlining actually occurs is subject to the compiler’s
heuristics.
The compiler heuristically decides which functions to inline. Different heuristics are
used when optimizing for speed, size, or when balancing between size and speed.
Normally, code size does not increase when optimizing for size.
81
AFE1_AFE2-1:1
Inlining functions
AFE1_AFE2-1:1
Functions
83
AFE1_AFE2-1:1
Inlining functions
AFE1_AFE2-1:1
Linking overview
● Linking—an overview
Linking—an overview
The IAR XLINK Linker is a powerful, flexible software tool for use in the development
of embedded applications. It is equally well suited for linking small, single-file, absolute
assembler programs as it is for linking large, relocatable, multi-module, C/C++, or
mixed C/C++ and assembler programs.
The linker combines one or more relocatable object files—produced by the IAR
Systems compiler or assembler—with required parts of object libraries to produce an
executable image containing machine code for the microcontroller you are using.
XLINK can generate more than 30 industry-standard loader formats, in addition to the
proprietary format UBROF which is used by the C-SPY debugger.
The linker will automatically load only those library modules that are actually needed
by the application you are linking. Furthermore, the linker eliminates segment parts that
are not required. During linking, the linker performs a full C-level type checking across
all modules.
The linker uses a configuration file where you can specify separate locations for code
and data areas of your target system memory map.
The final output produced by the linker is an absolute, target-executable object file that
can be downloaded to the microcontroller, to C-SPY, or to a compatible hardware
debugging probe. Optionally, the output file can contain debug information depending
on the output format you choose.
To handle libraries, the library tools XAR and XLIB can be used.
85
AFE1_AFE2-1:1
Segments and memory
WHAT IS A SEGMENT?
A segment is a container for pieces of data or code that should be mapped to a location
in physical memory. Each segment consists of one or more segment parts. Normally,
each function or variable with static storage duration is placed in its own segment part.
A segment part is the smallest linkable unit, which allows the linker to include only
those segment parts that are referred to. A segment can be placed either in RAM or in
ROM. Segments that are placed in RAM generally do not have any content, they only
occupy space.
Note: Here, ROM memory means all types of read-only memory, including flash
memory.
The compiler uses several predefined segments for different purposes. Each segment is
identified by a name that typically describes the contents of the segment, and has a
segment memory type. In addition to the predefined segments, you can also define your
own segments.
At compile time, the compiler assigns code and data to the various segments. The IAR
XLINK Linker is responsible for placing the segments in the physical memory range, in
accordance with the rules specified in the linker configuration file. Ready-made linker
configuration files are provided, but, if necessary, they can be modified according to the
requirements of your target system and application. It is important to remember that,
from the linker's point of view, all segments are equal; they are simply named parts of
memory.
AFE1_AFE2-1:1
Linking overview
87
AFE1_AFE2-1:1
Placing code and data—the linker configuration file
During the linking, XLINK might produce error messages and optionally a map file. In
the map file you can see the result of the actual linking and is useful for understanding
why an application was linked the way it was, for example, why a segment part was
included. If a segment part is not included although you expect it to be, the reason is
always that the segment part was not referenced to from an included part.
Note: To inspect the actual content of the object files, use XLIB. See the IAR Linker and
Library Tools Reference Guide.
AFE1_AFE2-1:1
Linking overview
The file consists of a sequence of linker commands. This means that the linking process
will be governed by all commands in sequence.
89
AFE1_AFE2-1:1
Initialization at system startup
Categories of Segment
Source Segment type Segment name*
declared data content
Zero-initialized int i; Read/write MEMATTR_Z None
data data, zero-init
Zero-initialized int i = 0; Read/write MEMATTR_Z None
data data, zero-init
Initialized data int i = 6; Read/write MEMATTR_I None
(non-zero) data
Initialized data int i = 6; Read-only data MEMATTR_ID Initializer data
(non-zero) for
MEMATTR_I
Constants const int i = 6; Read-only data MEMATTR_C The constant
Persistent data __persistent int Read-only MEMATTR_P The constant
i = 6; data†
Non-initialized __no_init int Read/write MEMATTR_AN None
absolute i @ 0x200; data
addressed data
Constant const int Read-only data MEMATTR_AC The constant
absolute i @ 0x200 =
addressed data 10000;
Non-initialized __no_init int i; Read/write MEMATTR_N None
data data
Table 7: segments holding initialized data
AFE1_AFE2-1:1
Linking overview
For more information about each segment, see the chapter Segment reference.
91
AFE1_AFE2-1:1
Stack usage analysis
If you enable stack usage analysis, a stack usage chapter will be added to the linker map
file, listing for each call graph root the particular call chain which results in the
maximum stack depth.
The analysis is only accurate if there is accurate stack usage information for each
function in the application.
In general, the compiler will generate this information for each C function, but if there
are indirect calls—calls using function pointers—in your application, you must supply
a list of possible functions that can be called from each calling function.
If you use a stack usage control file, you can also supply stack usage information for
functions in modules that do not have stack usage information.
You can use the check that directive in your stack usage control file to check that the
stack usage calculated by the linker does not exceed the stack space you have allocated.
AFE1_AFE2-1:1
Linking overview
You might need to specify more information to the linker to get a more representative
result. See Specifying additional stack usage information, page 95
In the IDE, choose Project>Options>Linker>Stack Usage>Enable stack usage
analysis>Control file.
On the command line, use the linker option --stack_usage_control.
See the IAR Linker and Library Tools Reference Guide for information about the linker
option --stack_usage_control.
6 To add an automatic check that you have allocated memory enough for the stack, use
the check that directive in your stack usage control file. For example, assuming a
stack segment named MY_STACK, you can write like this:
check that size("MY_STACK") >=maxstack("Program entry")
+ totalstack("interrupt") + 100;
When linking, the linker emits an error if the check fails. In this example, an error will
be emitted if the sum of the following exceeds the size of the MY_STACK segment:
● The maximum stack usage in the category Program entry (the main program).
● The sum of each individual maximum stack usage in the category interrupt
(assuming that all interrupt routines need space at the same time).
● A safety margin of 100 bytes (to account for stack usage not visible to the analysis).
See also check that directive, page 406 and Stack considerations, page 221.
93
AFE1_AFE2-1:1
Stack usage analysis
chain that results in the maximum stack depth for each call graph root. This is an
example of what the stack usage chapter in the map file might look like:
*****************************************************
* *
* STACK USAGE ANALYSIS *
* *
*****************************************************
Program entry
"__program_start": 0x0000c0f8
"__program_start" 0
"main" 4
"WriteObject" 24
"DumpObject" 0
"PrintObject" 8
"fprintf" 4
"_PrintfLarge" 126
"_PutstrLarge" 100
"pad" 14
"_PutcharsLarge" 10
"_FProut" 6
"fputc" 6
"_Fwprep" 6
"fseek" 4
"_Fspos" 14
"fflush" 6
"fflushOne" 6
"__write" 0
"__dwrite" 10
"__DebugBreak" 2
interrupt
"DoStuff()": 0x0000e9ee
"DoStuff()" 4
AFE1_AFE2-1:1
Linking overview
The summary contains the depth of the deepest call chain in each category as well as the
sum of the depths of the deepest call chains in that category.
Each call graph root belongs to a call graph root category to enable convenient
calculations in check that directives.
95
AFE1_AFE2-1:1
Stack usage analysis
If your interrupt functions have not already been designated as call graph roots by the
compiler, you must do so manually. You can do this either by using the #pragma
call_graph_root directive in your source code or by specifying a directive in your
suc file, for example:
call graph root [interrupt]: Irq1Handler, Irq2Handler;
See also call graph root directive, page 405 and call_graph_root, page 335.
● Specify a maximum number of iterations through any of the cycles in the recursion
nest of which the function is a member. In your suc file you can, for example, write
like this:
max recursion depth MyFunc12: 10;
● Selectively suppress the warning about unmentioned functions referenced by a
module for which you have supplied stack usage information in the stack usage
control file. Use the no calls from directive in your suc file, for example, like
this:
no calls from [file.r43] to MyFunc13, MyFunc14;
● Instead of specifying stack usage information about assembler modules in a stack
usage control file, you can annotate the assembler source with call frame
information. For more information, see the IAR Assembler User Guide for MSP430.
For more information, see the chapter The stack usage control file.
LIMITATIONS
Apart from missing or incorrect stack usage information, there are also other sources of
inaccuracy in the analysis:
● The linker cannot always identify all functions in object modules that lack stack
usage information. In particular, this might be a problem with object modules
written in assembler language. You can provide stack usage information for such
modules using a stack usage control file, and for assembler language modules you
can also annotate the assembler source code with CFI directives to provide stack
usage information. See the IAR Assembler User Guide for MSP430.
● If you use inline assembler to change the frame size or to perform function calls,
this will not be reflected in the analysis.
● Extra space consumed by other sources (the processor, an operating system, etc) is
not accounted for.
● The support for C++ is very incomplete. In particular virtual function calls, dynamic
objects, and various indirect calls from the standard library (like the functions set up
by set_new_handler and register_callback) are not supported at all.
● If you use other forms of function calls, they will not be reflected in the call graph.
AFE1_AFE2-1:1
Linking overview
● Using multi-file compilation (--mfc) can interfere with using a stack usage control
file to specify properties of module-local functions in the involved files.
Note: Stack usage analysis produces a worst case result. The program might not actually
ever end up in the maximum call chain, by design, or by coincidence.
Stack usage analysis is only a complement to actual measurement. If the result is
important, you need to perform independent validation of the results of the analysis.
97
AFE1_AFE2-1:1
Stack usage analysis
Example output:
Program entry:
0 __program_start [350]
0 __data16_memzero [2]
2 - [0]
0 __data16_memcpy [2]
0 memcpy [2]
2 - [0]
2 - [0]
0 main [350]
4 ParseObject [52]
28 GetObject [28]
34 getc [22]
38 _Frprep [18]
44 malloc [12]
44 __data16_malloc [12]
48 __data16_findmem [8]
52 __data16_free [4]
56 - [0]
52 __data16GetMemChunk [2]
54 - [0]
46 - [0]
44 __read [12]
54 __DebugBreak [2]
56 - [0]
36 - [0]
34 CreateObject [18]
40 malloc [12] ***
4 ProcessObject [326]
8 ProcessHigh [76]
34 ProcesMedium [50]
60 ProcessLow [24]
84 - [0]
8 DumpObject [322]
8 PrintObject [322]
16 fprintf [314]
20 _PrintfLarge [310]
10 - [0]
4 WriteObject [346]
28 DumpObject [322] ***
4 DestroyObject [28]
28 free [4]
28 __data16_free [4] ***
30 - [0]
0 exit [38]
0 _exit [38]
4 _Close_all [34]
AFE1_AFE2-1:1
Linking overview
8 fclose [30]
14 _Fofree [4]
14 free [4] ***
16 - [0]
14 fflush [24] ***
14 free [4] ***
14 __close [8]
20 __DebugBreak [2] ***
14 remove [8]
20 __DebugBreak [2] ***
8 __write [12] ***
2 __exit [8]
8 __DebugBreak [2] ***
2 - [0]
99
AFE1_AFE2-1:1
Stack usage analysis
AFE1_AFE2-1:1
Linking your application
● Linking considerations
Linking considerations
When you set up your project in the IAR Embedded Workbench IDE, a default linker
configuration file is automatically used based on your project settings and you can
simply link your application. For the majority of all projects it is sufficient to configure
the vital parameters that you find in Project>Options>Linker>Config.
When you build from the command line, you can use a ready-made linker command file
provided with your product package.
The config directory contains the information required by XLINK, and are ready to be
used as is. The only change, if any, you will normally have to make to the supplied
configuration file is to customize it so it fits the target system memory map. If, for
example, your application uses additional external RAM, you must also add details
about the external RAM memory area.
To edit a linker configuration file, use the editor in the IDE, or any other suitable editor.
Do not change the original template file. We recommend that you make a copy in the
working directory, and modify the copy instead.
If you find that the default linker configuration file does not meet your requirements, you
might want to consider:
● Placing segments
● Placing data
● Setting up stack memory
● Setting up heap memory
● Placing code
● Keeping modules
● Keeping symbols and segments
● Application startup
● Interaction between XLINK and your application
● Producing other output formats than UBROF
101
AFE1_AFE2-1:1
Linking considerations
PLACING SEGMENTS
The placement of segments in memory is performed by the IAR XLINK Linker.
This section describes the most common linker commands and how to customize the
linker configuration file to suit the memory layout of your target system. In
demonstrating the methods, fictitious examples are used.
In demonstrating the methods, fictitious examples are used based on this memory
layout:
● There is 1 Mbyte addressable memory.
● There is ROM memory in the address ranges 0x0000–0x1FFF, 0x3000–0x4FFF,
and 0x10000–0x1FFFF.
● There is RAM memory in the address ranges 0x8000–0xAFFF, 0xD000–0xFFFF,
and 0x20000–0x27FFF.
● There are two addressing modes for data, one for data16 memory and one for
data20 memory.
● There is one stack and one heap.
● There are two addressing modes for code, one for near_func memory and one for
far_func memory.
Note: Even though you have a different memory map, for example if you have
additional memory spaces (EEPROM) and additional segments, you can still use the
methods described in the following examples.
The ROM can be used for storing CONST and CODE segment memory types. The RAM
memory can contain segments of DATA type. The main purpose of customizing the linker
configuration file is to verify that your application code and data do not cross the
memory range boundaries, which would lead to application failure.
For the result of each placement directive after linking, inspect the segment map in the
list file (created by using the command line option -x).
AFE1_AFE2-1:1
Linking your application
● When placing code and data segments for different addressing modes, make sure to
place the segments in size order (the smallest memory type first).
Note: Before the linker places any segments in memory, the linker will first place the
absolute segments.
To place two segments of different types contiguous in the same memory area, do not
specify a range for the second segment. In the following example, the MYSEGMENTA
segment is first located in memory. Then, the rest of the memory range could be used by
MYCODE.
-Z(CONST)MYSEGMENTA=0000-1FFF
-Z(CODE)MYCODE
Two memory ranges can overlap. This allows segments with different placement
requirements to share parts of the memory space; for example:
-Z(CONST)MYSMALLSEGMENT=0000-01FF
-Z(CONST)MYLARGESEGMENT=0000-1FFF
Even though it is not strictly required, make sure to always specify the end of each
memory range. If you do this, the IAR XLINK Linker will alert you if your segments do
not fit in the available memory.
103
AFE1_AFE2-1:1
Linking considerations
If your application has an additional RAM area in the memory range 0x6000-0x67FF,
you can simply add that to the original definition:
-P(DATA)MYDATA=8000-AFFF,D000-FFFF,6000–67FF
The linker can then place some parts of the MYDATA segment in the first range, and some
parts in the second range. If you had used the -Z command instead, the linker would
have to place all segment parts in the same range.
Note: Copy initialization segments—BASENAME_I and BASENAME_ID—and dynamic
initialization segments must be placed using -Z. For code placed in RAM, see Code in
RAM, page 108.
PLACING DATA
Static memory is memory that contains variables that are global or declared static.
All the data segments are placed in the area used by on-chip RAM.
AFE1_AFE2-1:1
Linking your application
Note that the size is written hexadecimally, but not necessarily with the 0x notation.
In many linker configuration files provided with IAR Embedded Workbench, this line is
prefixed with the comment character // because the IDE controls the stack size
allocation. To make the directive take effect, remove the comment character.
Note:
● This range does not specify the size of the stack; it specifies the range of the
available memory.
105
AFE1_AFE2-1:1
Linking considerations
● The # allocates the CSTACK segment at the end of the memory area. Typically, this
means that the stack will get all remaining memory at the same time as it is
guaranteed that it will be at least _CSTACK_SIZE bytes in size.
Note that the size is written hexadecimally, but not necessarily with the 0x notation.
In many linker configuration files provided with IAR Embedded Workbench, these lines
are prefixed with the comment character // because the IDE controls the heap size
allocation. To make the directive take effect, remove the comment character.
If you use a heap, you should allocate at least 512 bytes for it, to make it work properly.
AFE1_AFE2-1:1
Linking your application
Note: This range does not specify the size of the heap; it specifies the range of the
available memory.
PLACING CODE
This section contains descriptions of the segments used for storing code and the
interrupt vector table. For information about all segments, see Summary of segments,
page 387.
Startup code
In this example, the segment CSTART contains code used during system startup and
termination, see System startup and termination, page 135. The segment parts must also
be placed into one continuous memory space, which means that the -P segment
directive cannot be used.
This line will place the CSTART segment at the address 0x1100:
-Z(CODE)CSTART=1100
Interrupt vectors
The interrupt vector table contains pointers to interrupt routines, including the reset
routine. In this example, the table is placed in the segment INTVEC. For the MSP430
microcontroller, it typically ends at address 0xFFFF. For a device with 16 interrupt
vectors, this means that the segment should start at the address 0xFFE0, for example:
-Z(CONST)INTVEC=FFE0-FFFF
The system startup code places the reset vector in the RESET segment; the INTVEC
segment cannot be used by the system startup code because the size of the interrupt
107
AFE1_AFE2-1:1
Linking considerations
vector table varies between different devices. In the linker configuration file it can look
like this:
-Z(CONST)RESET=FFFE-FFFF
An application that does not use the standard startup code can either use the RESET
segment, or define an interrupt function on the reset vector, in which case the INTVEC
segment is used.
For more information about the interrupt vectors, see Interrupt vectors and the interrupt
vector table, page 73.
Code in RAM
The segment CODE_I holds code which executes in RAM and which was initialized by
CODE_ID.
The linker configuration file uses the XLINK option -Q to specify automatic setup for
copy initialization of segments. This will cause the linker to generate a new initializer
segment into which it will place all data content of the code segment. Everything else,
such as symbols and debugging information, will still be associated with the code
segment. Code in the application must at runtime copy the contents of the initializer
segment in ROM to the code segment in RAM. This is very similar to how initialized
variables are treated.
-QCODE_I=CODE_ID
DIFUNCT must be placed using -Z. For more information, see DIFUNCT, page 398.
KEEPING MODULES
If a module is linked as a program module, it is always kept. That is, it will contribute
to the linked application. However, if a module is linked as a library module, it is
AFE1_AFE2-1:1
Linking your application
included only if it is symbolically referred to from other parts of the application that
have been included. This is true, even if the library module contains a root symbol. To
assure that such a library module is always included, use the linker option -A to make
all modules in the file be treaded as if they were program modules:
-A file.r43
Use -C to makes all modules in the file be treated as if they were library modules:
-C file.r43
APPLICATION STARTUP
By default, the point where the application starts execution is defined by the
__program_start label, which is defined to point at the start of code. The label is also
communicated via the debugger information to any debugger.
To change the start point of the application to another label, use the XLINK option -s.
109
AFE1_AFE2-1:1
Verifying the linked result of code and data placement
Note that it can be useful to use the XLINK -O option to produce two output files, one
for debugging and one for burning to ROM/flash.
Note also that if you choose to enable debug support using the -r option for certain
low-level I/O functionality for mechanisms like file operations on the host computer etc,
such debug support might have an impact on the performance and responsiveness of
your application. In this case, the debug build will differ from your release build due to
the debug modules included.
AFE1_AFE2-1:1
Linking your application
● A module map which lists all segments, local symbols, and entries (public symbols)
for every module in the program. All symbols not included in the output can also be
listed
● A module summary which lists the contribution (in bytes) from each module
● A symbol list which contains every entry (global symbol) in every module.
Use the option Generate linker listing in the IDE, or the option -x on the command
line, and one of their suboptions to generate a linker listing.
Normally, XLINK will not generate an output file if any errors, such as range errors,
occur during the linking process. Use the option Always generate output in the IDE,
or the option -B on the command line, to generate an output file even if a non-fatal error
was encountered.
For more information about the listing options and the linker listing, see the IAR Linker
and Library Tools Reference Guide, and the IDE Project Management and Building
Guide.
111
AFE1_AFE2-1:1
Checking module consistency
Example
In this table, the object files could (but do not have to) define the two runtime attributes
color and taste:
In this case, file1 cannot be linked with any of the other files, since the runtime
attribute color does not match. Also, file4 and file5 cannot be linked together,
because the taste runtime attribute does not match.
On the other hand, file2 and file3 can be linked with each other, and with either
file4 or file5, but not with both.
Alternatively, you can also use the rtmodel assembler directive to specify runtime
model attributes in your assembler source code. For example:
rtmodel "uart", "mode1"
Note: Key names that start with two underscores are reserved by the compiler. For more
information about the syntax, see rtmodel, page 349 and the IAR Assembler User Guide
for MSP430.
Note: The predefined runtime attributes all start with two underscores. Any attribute
names you specify yourself should not contain two initial underscores in the name, to
eliminate any risk that they will conflict with future IAR runtime attribute names.
At link time, the IAR XLINK Linker checks module consistency by ensuring that
modules with conflicting runtime attributes will not be used together. If conflicts are
detected, an error is issued.
AFE1_AFE2-1:1
Linking your application
The easiest way to find the proper settings of the RTMODEL directive is to compile a C or
C++ module to generate an assembler file, and then examine the file.
If you are using assembler routines in the C or C++ code, see the chapter Assembler
directives in the IAR Assembler User Guide for MSP430.
113
AFE1_AFE2-1:1
Checking module consistency
AFE1_AFE2-1:1
The DLIB runtime
environment
● Introduction to the runtime environment
DLIB can be used with both the C and the C++ languages. CLIB, on the other
hand, can only be used with the C language. For more information about CLIB,
see the chapter The CLIB runtime environment.
115
AFE1_AFE2-1:1
Introduction to the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
the low-level part of the standard I/O interface is not completely implemented by
default:
117
AFE1_AFE2-1:1
Introduction to the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
default, the functions in the low-level interface lack usable implementations. Some are
unimplemented, others have stub implementations that do not perform anything except
returning error codes.
To retarget the standard I/O interface, all you have to do is to provide implementations
for the functions in the DLIB low-level I/O interface.
For example, if your application calls the functions printf and fputc in the standard
I/O interface, the implementations of those functions both call the low-level function
__write to output individual characters. To make them work, you just need to provide
an implementation of the __write function—either by implementing it yourself, or by
using a third-party implementation.
For information about how to override library modules with your own implementations,
see Overriding library modules, page 123. See also The DLIB low-level I/O interface,
page 139 for information about the functions that are part of the interface.
119
AFE1_AFE2-1:1
Setting up the runtime environment
Linker
Linker option in the
command line Description
IDE
option
Debug information -Fubrof Debug support for C-SPY, but without any support
for C-SPY for C-SPY emulated I/O.
With runtime -r The same as -Fubrof but also limited support for
control modules C-SPY emulated I/O handling program abort, exit,
and assertions.
Table 10: Debug information and levels of C-SPY emulated I/O
AFE1_AFE2-1:1
The DLIB runtime environment
Linker
Linker option in the
command line Description
IDE
option
With I/O emulation -rt Full support for C-SPY emulated I/O, which means
modules the same as -r, but also support for I/O handling,
and accessing files on the host computer during
debugging.
Table 10: Debug information and levels of C-SPY emulated I/O (Continued)
Note: The C-SPY Terminal I/O window is not opened automatically; you must open it
manually. For more information about this window, see the C-SPY® Debugging Guide
for MSP430.
5 On some systems, terminal output might be slow because the host computer and the
target system must communicate for each character.
For this reason, a replacement for the __write function called __write_buffered is
included in the runtime library. This module buffers the output and sends it to the
debugger one line at a time, speeding up the output. Note that this function uses about
80 bytes of RAM memory.
To use this feature in the IDE, choose Project>Options>Linker>Output and select the
option Buffered terminal output.
To enable this function on the command line, add this to the linker command line:
-e__write_buffered=__write
6 Some math functions are available in different versions: default versions, smaller than
the default versions, and larger but more accurate than default versions. Consider
which versions you should use.
To specify which set of the math functions to use, choose Project>Options>General
Options>Library Options>Math functions and choose which set to use. You can also
specify individual functions.
For more information, see Math functions, page 131.
7 When you build your project, a suitable prebuilt library and library configuration file
are automatically used based on the project settings you made.
For information about which project settings affect the choice of library file, see
Runtime library configurations, page 126.
You have now set up a runtime environment that can be used while developing your
application source code.
121
AFE1_AFE2-1:1
Setting up the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
3 When you have implemented your functions of the low-level I/O interface, you must
add your version of these functions to your project. For information about this, see
Overriding library modules, page 123.
Note: If you have implemented a DLIB low-level I/O interface function and added it to
a project that you have built with support for C-SPY emulated I/O, your low-level
function will be used and not the functions provided with C-SPY emulated I/O. For
example, if you implement your own version of __write, output to the C-SPY
Terminal I/O window will not be supported. See Briefly about C-SPY emulated I/O,
page 118.
4 Before you can execute your application on your target system, you must rebuild your
project with a Release build configuration. This means that the linker will not include
the C-SPY emulated I/O mechanism and the low-level I/O functions it provides. If your
application calls any of the low-level functions of the standard I/O interface, either
directly or indirectly, and your project does not contain these, the linker will issue an
error for every missing low-level function.
Note: By default, the NDEBUG symbol is defined in a Release build configuration, which
means asserts will no longer be checked. For more information, see __ReportAssert,
page 145.
123
AFE1_AFE2-1:1
Setting up the runtime environment
The library files that you can override with your own versions are located in the
430\src\lib directory.
AFE1_AFE2-1:1
The DLIB runtime environment
For information about configuration symbols that you might want to customize, see:
● Configuration symbols for printf and scanf, page 148
● Configuration symbols for file input and output, page 149
● Locale, page 149
● Strtod, page 151
● Managing a multithreaded environment, page 154
2 When you are finished, build your library project with the appropriate project options.
After you build your library, you must make sure to use it in your application project.
To build IAR Embedded Workbench projects from the command line, use the IAR
Command Line Build Utility (iarbuild.exe). However, no make or batch files for
building the library from the command line are provided.For information about the build
process and the IAR Command Line Build Utility, see the IDE Project Management and
Building Guide.
125
AFE1_AFE2-1:1
Additional information on the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
Note: In addition to these predefined library configurations, you can provide your own
configuration, see Customizing and building your own runtime library, page 124
If you do not specify a library configuration explicitly you will get the default
configuration. If you use a prebuilt runtime library, a configuration file that matches the
runtime library file will automatically be used. See Setting up the runtime environment,
page 119.
To override the default library configuration, use one of these methods:
1 Use a prebuilt configuration of your choice—to specify a runtime configuration
explicitly:
Choose Project>Options>General Options>Library Configuration>Library and
change the default setting.
Use the --dlib_config compiler option, see --dlib_config, page 277.
The prebuilt libraries are based on the default configurations, see Runtime library
configurations, page 126.
2 If you have built your own customized library, choose Project>Options>General
Options>Library Configuration>Library and choose Custom to use your own
configuration. For more information, see Customizing and building your own runtime
library, page 124.
127
AFE1_AFE2-1:1
Additional information on the runtime environment
Note: All modules in the library have a name that starts with the character ? (question
mark).
You can find the library object files in the subdirectory 430\lib\dlib and the library
configuration files in the 430\inc\dlib subdirectory.
For example, the library dl430xsmdfrt.r43 is configured for DLIB, the MSP430X
core, the Small code model, the Medium data model, 64-bit double, the full library
AFE1_AFE2-1:1
The DLIB runtime environment
129
AFE1_AFE2-1:1
Additional information on the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
the linker to select the full formatter. In this case, you might want to override the
automatically selected scanf formatter.
To manually specify the scanf formatter in the IDE:
1 Choose Project>Options>General Options to open the Options dialog box.
2 On the Library Options page, select the appropriate formatter.
To manually specify the scanf formatter from the command line:
1 Add one of these lines in the linker configuration file you are using:
-e_ScanfFull=_Scanf
-e_ScanfFullNoMb=_Scanf
-e_ScanfLarge=_Scanf
-e_ScanfLargeNoMb=_Scanf
_e_ScanfSmall=_Scanf
_e_ScanfSmallNoMb=_Scanf
MATH FUNCTIONS
Some C/C++ standard library math functions are available in different versions:
● The default versions
● Smaller versions (but less accurate)
● More accurate versions (but larger).
131
AFE1_AFE2-1:1
Additional information on the runtime environment
Smaller versions
The functions cos, exp, log, log2, log10, __iar_Log (a help function for log, log2,
and log10), pow, sin, tan, and __iar_Sin (a help function for sin and cos) exist in
additional, smaller versions in the library. They are about 20% smaller and about 20%
faster than the default versions. The functions handle INF and NaN values. The
drawbacks are that they almost always lose some precision and they do not have the
same input range as the default versions.
The names of the functions are constructed like:
__iar_xxx_small<f|l>
where f is used for float variants, l is used for long double variants, and no suffix
is used for double variants.
To specify which set of math functions to use:
1 Choose Project>Options>General Options>Library Options>Math functions and
choose which set to use.
2 Link your application and the chosen set will be used.
To specify a complete set of math functions from the command line:
1 Use the -f option to extend the XLINK command line with the appropriate file:
double
Extended command line file Texas Instruments MathLib is used
size
dlib_small_math.xcl no any
dlib_small_math_mathlib32.xcl yes 32 bits
dlib_small_math_mathlib64.xcl yes 64 bits
Table 14: Extended command line files for the small math functions
AFE1_AFE2-1:1
The DLIB runtime environment
-e__iar_sin_smallf=sinf
-e__iar_cos_smallf=cosf
-e__iar_tan_smallf=tanf
-e__iar_log_smallf=logf
-e__iar_log2_smallf=log2f
-e__iar_log10_smallf=log10f
-e__iar_exp_smallf=expf
-e__iar_pow_smallf=powf
-e__iar_Sin_smallf=__iar_Sinf
-e__iar_Log_smallf=__iar_Logf
-e__iar_sin_smalll=sinl
-e__iar_cos_smalll=cosl
-e__iar_tan_smalll=tanl
-e__iar_log_smalll=logl
-e__iar_log2_smalll=log2l
-e__iar_log10_smalll=log10l
-e__iar_exp_smalll=expl
-e__iar_pow_smalll=powl
-e__iar_Sin_smalll=__iar_Sinl
-e__iar_Log_smalll=__iar_Logl
Note that if you want to redirect any of the functions sin, cos, or __iar_Sin, you must
redirect all three functions.
Note that if you want to redirect any of the functions log, log2, log10, or __iar_Log,
you must redirect all four functions.
133
AFE1_AFE2-1:1
Additional information on the runtime environment
argument ranges. The drawback is that they are larger and slower than the default
versions.
The names of the functions are constructed like:
__iar_xxx_accurate<f|l>
where f is used for float variants, l is used for long double variants, and no suffix
is used for double variants.
To specify individual math functions from the command line:
1 Redirect the default function names to these names when linking, using these options:
-e__iar_sin_accurate=sin
-e__iar_cos_accurate=cos
-e__iar_tan_accurate=tan
-e__iar_pow_accurate=pow
-e__iar_Sin_accurate=__iar_Sin
-e__iar_Pow_accurate=__iar_Pow
-e__iar_sin_accuratef=sinf
-e__iar_cos_accuratef=cosf
-e__iar_tan_accuratef=tanf
-e__iar_pow_accuratef=powf
-e__iar_Sin_accuratef=__iar_Sinf
-e__iar_Pow_accuratef=__iar_Powf
-e__iar_sin_accuratel=sinl
-e__iar_cos_accuratel=cosl
-e__iar_tan_accuratel=tanl
-e__iar_pow_accuratel=powl
-e__iar_Sin_accuratel=__iar_Sinl
-e__iar_Pow_accuratel=__iar_Powl
Note that if you want to redirect any of the functions sin, cos, or __iar_Sin, you must
redirect all three functions.
Note that if you want to redirect any of the functions pow or __iar_Pow, you must
redirect both functions.
AFE1_AFE2-1:1
The DLIB runtime environment
For information about how to customize the system startup code, see System
initialization, page 138.
System startup
During system startup, an initialization sequence is executed before the main function
is entered. This sequence performs initializations required for the target hardware and
the C/C++ environment.
For the hardware initialization, it looks like this:
● When the CPU is reset it will start executing at the program entry label
__program_start in the system startup code.
135
AFE1_AFE2-1:1
Additional information on the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
System termination
This illustration shows the different ways an embedded application can terminate in a
controlled way:
137
AFE1_AFE2-1:1
Additional information on the runtime environment
The library files that you can override with your own versions are located in the
430\src\lib directory. See Overriding library modules, page 123.
SYSTEM INITIALIZATION
It is likely that you need to adapt the system initialization. For example, your application
might need to initialize memory-mapped special function registers (SFRs), or omit the
default initialization of data segments performed by the system startup code.
You can do this by implementing your own version of the routine __low_level_init,
which is called from the cstartup.s43 file before the data segments are initialized.
Modifying the cstartup.s43 file directly should be avoided.
The code for handling system startup is located in the source files cstartup.s43 and
low_level_init.c, located in the 430\src\lib directory.
Note that normally, you do not need to customize either of the files cstartup.s43 or
cexit.s43.
Customizing __low_level_init
The value returned by __low_level_init determines whether or not data segments
should be initialized by the system startup code. If the function returns 0, the data
segments will not be initialized.
Note: The file intrinsics.h must be included by low_level_init.c to assure
correct behavior of the __low_level_init routine.
AFE1_AFE2-1:1
The DLIB runtime environment
Note: You must make sure that the linker uses the start label used in your version of
cstartup.s43. For information about how to change the start label used by the linker,
read about the -s option in the IAR Linker and Library Tools Reference Guide.
Note: You should not use the low-level functions prefixed with __ directly in your
application. Instead you should use the standard library functions that use these
functions. For example, to write to stdout, you should use standard library functions
like printf or puts, which in turn calls the low-level function __write. If you have
forgot to implement a low-level function and your application will call that function via
139
AFE1_AFE2-1:1
Additional information on the runtime environment
a standard library function, the linker will issues an error when you link in release build
configuration.
Note: If you implement your own variants of the functions in this interface, your
variants will be used even though you have enabled C-SPY emulated I/O, see Briefly
about C-SPY emulated I/O, page 118.
abort
Source file 430\src\lib\dlib\abort.c
C-SPY debug action Notifies that the application has called abort.
clock
Source file 430\src\lib\dlib\clock.c
__close
Source file 430\src\lib\dlib\close.c
C-SPY debug action Closes the associated host file on the host computer.
AFE1_AFE2-1:1
The DLIB runtime environment
__exit
Source file 430\src\lib\dlib\xxexit.c
C-SPY debug action Notifies that the end of the application was reached.
getenv
Source file 430\src\lib\dlib\getenv.c
430\src\lib\dlib\environ.c
Default implementation The getenv function in the library searches the string pointed to by the global variable
__environ, for the key that was passed as argument. If the key is found, the value of it
is returned, otherwise 0 (zero) is returned. By default, the string is empty.
To create or edit keys in the string, you must create a sequence of null-terminated strings
where each string has the format:
key=value\0
End the string with an extra null character (if you use a C string, this is added
automatically). Assign the created sequence of strings to the __environ variable.
For example:
const char MyEnv[] = "Key=Value\0Key2=Value2\0";
__environ = MyEnv;
If you need a more sophisticated environment variable handling, you should implement
your own getenv, and possibly putenv function.
Note: The putenv function is not required by the standard, and the library does not
provide an implementation of it.
141
AFE1_AFE2-1:1
Additional information on the runtime environment
__getzone
Source file 430\src\lib\dlib\getzone.c
__lseek
Source file 430\src\lib\dlib\lseek.c
Description Low-level function for changing the location of the next access in an open file.
C-SPY debug action Searches in the associated host file on the host computer.
__open
Source file 430\src\lib\dlib\open.c
AFE1_AFE2-1:1
The DLIB runtime environment
raise
Source file 430\src\lib\dlib\raise.c
Default implementation Calls the signal handler for the raised signal, or terminates with call to
__exit(EXIT_FAILURE).
__read
Source file 430\src\lib\dlib\read.c
Description Low-level function that reads characters from stdin and from files.
C-SPY debug action Directs stdin to the Terminal I/O window. All other files will read the associated host
file.
143
AFE1_AFE2-1:1
Additional information on the runtime environment
Example The code in this example uses memory-mapped I/O to read from a keyboard, whose port
is assumed to be located at 40:
#include <stddef.h>
*buf++ = c;
++nChars;
}
return nChars;
}
For information about the handles associated with the streams, see Retargeting—
Adapting for your target system, page 122.
For information about the @ operator, see Controlling data and function placement in
memory, page 236.
remove
Source file 430\src\lib\dlib\remove.c
AFE1_AFE2-1:1
The DLIB runtime environment
C-SPY debug action Writes a message to the Debug Log window and returns -1.
rename
Source file 430\src\lib\dlib\rename.c
__ReportAssert
Source file 430\src\lib\dlib\xreportassert.c
C-SPY debug action Notifies the C-SPY debugger about the failed assert.
Default implementation Failed asserts are reported by the function __ReportAssert. By default, it prints an
error message and calls abort. If this is not the behavior you require, you can
implement your own version of the function.
The assert macro is defined in the header file assert.h. To turn off assertions, define
the symbol NDEBUG.
In the IDE, the symbol NDEBUG is by default defined in a Release project and not defined
in a Debug project. If you build from the command line, you must explicitly define the
symbol according to your needs. See NDEBUG, page 375.
signal
Source file 430\src\lib\dlib\signal.c
145
AFE1_AFE2-1:1
Additional information on the runtime environment
Default implementation As specified by Standard C. You might want to modify this behavior if the environment
supports some kind of asynchronous signals.
system
Source file 430\src\lib\dlib\system.c
C-SPY debug action Notifies the C-SPY debugger that system has been called and then returns -1.
Default implementation If you need to use the system function, you must implement it yourself. The system
function available in the library returns 0 if a null pointer is passed to it to indicate that
there is no command processor; otherwise it returns -1 to indicate failure. If this is not
the functionality that you require, you can implement your own version. This does not
require that you rebuild the library.
__time32, __time64
Source file 430\src\lib\dlib\time.c
430\src\lib\dlib\time64.c
__write
Source file 430\src\lib\dlib\write.c
AFE1_AFE2-1:1
The DLIB runtime environment
C-SPY debug action Directs stdout and stderr to the Terminal I/O window. All other files will write to
the associated host file.
Example The code in this example uses memory-mapped I/O to write to an LCD display, whose
port is assumed to be located at address 40:
#include <stddef.h>
return nChars;
}
For information about the handles associated with the streams, see Retargeting—
Adapting for your target system, page 122.
147
AFE1_AFE2-1:1
Additional information on the runtime environment
When you build a library, these configurations determine what capabilities the function
scanf should have:
AFE1_AFE2-1:1
The DLIB runtime environment
LOCALE
Locale is a part of the C language that allows language- and country-specific settings for
several areas, such as currency symbols, date and time, and multibyte character
encoding.
Depending on which library configuration you are using, you get different level of locale
support. However, the more locale support, the larger your code will get. It is therefore
necessary to consider what level of support your application needs. See Runtime library
configurations, page 126.
The DLIB runtime library can be used in two main modes:
● With locale interface, which makes it possible to switch between different locales
during runtime
● Without locale interface, where one selected locale is hardwired into the
application.
149
AFE1_AFE2-1:1
Additional information on the runtime environment
#define _DLIB_FULL_LOCALE_SUPPORT 1
#define _LOCALE_USE_C /* C locale */
#define _LOCALE_USE_EN_US /* American English */
#define _LOCALE_USE_EN_GB /* British English */
#define _LOCALE_USE_SV_SE /* Swedish in Sweden */
AFE1_AFE2-1:1
The DLIB runtime environment
or
lang_REGION.encoding
The lang part specifies the language code, and the REGION part specifies a region
qualifier, and encoding specifies the multibyte character encoding that should be used.
The lang_REGION part matches the _LOCALE_USE_LANG_REGION preprocessor
symbols that can be specified in the library configuration file.
Example
This example sets the locale configuration symbols to Swedish to be used in Finland and
UTF8 multibyte character encoding:
STRTOD
The function strtod does not accept hexadecimal floating-point strings in libraries
with the normal library configuration. To make strtod accept hexadecimal
floating-point strings, you must:
1 Enable the configuration symbol _DLIB_STRTOD_HEX_FLOAT in the library
configuration file.
2 Rebuild the library, see Customizing and building your own runtime library, page 124.
151
AFE1_AFE2-1:1
Additional information on the runtime environment
Specify which runtime library object file to use on the XLINK command line.
In addition to the runtime library object file, you must extend the XLINK command line
with an additional linker configuration file. To use the hardware multiplier, use the
command line option -f to extend the XLINK command line with the appropriate
extended command line file:
Linker configuration file Type of hardware multiplier
multiplier.xcl 16 or 16s
multiplier32.xcl 32
Table 18: Additional linker configuration files for the hardware multiplier
MPU/IPE SUPPORT
AFE1_AFE2-1:1
The DLIB runtime environment
You must also define the hexadecimal values that will be put in the MPUSAM and
MPUCTL0 registers, respectively, using for example:
-D__iar_430_MPUSAM_value=1573
-D__iar_430_MPUCTL0_value=0001
If the automatic setup for the MPU does not suit your application, you can manually
override the module ?MpuInit with your own implementation, without rebuilding the
runtime library.
You must also define the hexadecimal value that will be put in the MPUIPC0 register,
using for example:
-D__iar_430_MPUIPC0_value=0040
153
AFE1_AFE2-1:1
Managing a multithreaded environment
If the automatic setup for the IPE does not suit your application, you can manually
override the module ?IpeInit with your own implementation, without rebuilding the
runtime library.
Note: Once IPE has been enabled on a device, the IPE area will remain locked until
cleared.
To clear the IPE area when downloading an application, select
Project>Options>Debugger>FET Debugger>Download>Erase main and
Information memory inc. IP PROTECTED area.
AFE1_AFE2-1:1
The DLIB runtime environment
Note: If you are using printf/scanf (or any variants) with formatters, each individual
formatter will be guarded, but the complete printf/scanf invocation will not be
guarded.
If one of the C++ variants is used together with the DLIB runtime environment with
multithread support, the compiler option --guard_calls must be used to make sure
that function-static variables with dynamic initializers are not initialized simultaneously
by several threads.
155
AFE1_AFE2-1:1
Managing a multithreaded environment
2 To complement the built-in multithread support in the runtime library, you must also:
● Implement code for the library’s system locks interface, see System locks interface,
page 156.
● If file streams are used, implement code for the library’s file stream locks interface
or redirect the interface to the system locks interface (using the linker option -e),
see File streams locks interface, page 156.
● Implement code that handles thread creation, thread destruction, and TLS access
methods for the library, see TLS handling, page 157.
See also Lock usage, page 157 for information about used file streams locks and system
locks.
You can find the required declaration of functions and definitions of macros in the
DLib_Threads.h file, which is included by yvals.h.
AFE1_AFE2-1:1
The DLIB runtime environment
Lock usage
The number of locks that the DLIB runtime environment assumes exist are:
● _FOPEN_MAX—the maximum number of file stream locks. These locks are only
used in the Full library configuration, in other words only if both the macro symbols
_DLIB_FILE_DESCRIPTOR and _FILE_OP_LOCKS are true.
● _MAX_LOCK—the maximum number of system locks.
Note that even if the application uses fewer locks, the runtime environment will initialize
and destroy all the locks above.
For information about the initialization and destruction code, see xsyslock.c.
TLS handling
The DLIB runtime environment supports TLS memory areas for two types of threads:
the main thread (the main function including the system startup and exit code) and
secondary threads.
The main thread’s TLS memory area:
● Is automatically created and initialized by your application’s startup sequence
● Is automatically destructed by the application’s destruct sequence
● Is located in the segment TLS16_I
● Exists also for non-threaded applications.
Each secondary thread’s TLS memory area:
● Must be manually created and initialized
● Must be manually destructed
● Is located in a manually allocated memory area.
If you need the runtime library to support secondary threads, you must override the
function:
void *__iar_dlib_perthread_access(void *symbp);
The parameter is the address to the TLS variable to be accessed—in the main thread’s
TLS area—and it should return the address to the symbol in the current TLS area.
157
AFE1_AFE2-1:1
Managing a multithreaded environment
Two interfaces can be used for creating and destroying secondary threads. You can use
the following interface that allocates a memory area on the heap and initializes it. At
deallocation, it destroys the objects in the area and then frees the memory.
void *__iar_dlib_perthread_allocate(void);
void __iar_dlib_perthread_deallocate(void *);
Alternatively, if the application handles the TLS allocation, you can use this interface
for initializing and destroying the objects in the memory area:
void __iar_dlib_perthread_initialize(void *);
void __iar_dlib_perthread_destroy(void *);
These macros can be helpful when you implement an interface for creating and
destroying secondary threads:
Macro Description
__IAR_DLIB_PERTHREAD_SIZE The size needed for the TLS memory area.
__IAR_DLIB_PERTHREAD_INIT_SIZE The initializer size for the TLS memory area.
You should initialize the rest of the TLS
memory area, up to
__IAR_DLIB_PERTHREAD_SIZE to zero.
__IAR_DLIB_PERTHREAD_SYMBOL_ The offset to the symbol in the TLS memory
OFFSET(symbolptr) area.
Table 20: Macros for implementing TLS allocation
Note that the size needed for TLS variables depends on which resources in the DLIB
runtime environment your application uses.
AFE1_AFE2-1:1
The DLIB runtime environment
p += __IAR_DLIB_PERTHREAD_SYMBOL_OFFSET(symbp);
return (void _DLIB_TLS_MEMORY *) p;
}
The TLSp variable is unique for each thread, and must be exchanged by the RTOS or
manually whenever a thread switch occurs.
159
AFE1_AFE2-1:1
Managing a multithreaded environment
Both the TLS16_I segment and the TLS16_ID segment must be placed in default
memory for RAM and ROM, respectively.
The startup code will copy TLS16_ID to TLS16_I.
AFE1_AFE2-1:1
The CLIB runtime
environment
● Using a prebuilt runtime library
● MPU/IPE support
Note: The CLIB runtime environment does not support any C99 functionality. For
example, complex numbers and variable length arrays are not supported. Neither does
CLIB support C++.
The legacy CLIB runtime environment is provided for backward compatibility
and should not be used for new application projects. Among other things, it
does not support ROPI nor multithreading.
For information about migrating from CLIB to DLIB, see the IAR Embedded
Workbench® Migration Guide.
161
AFE1_AFE2-1:1
Input and output
The CLIB runtime environment includes the C standard library. The linker will include
only those routines that are required—directly or indirectly—by your application. For
more information about the runtime libraries, see the chapter C/C++ standard library
functions.
where
● {lib} cl for the CLIB runtime library
● {core} is either 430 or 430X
● {code_model} is empty for MSP430 devices. For MSP430X devices, it is one of s
or l, for the Small and Large code model, respectively
● {data_model} is empty for MSP430 devices. For MSP430X devices, it is one of s,
m, or l, for the Small, Medium, and Large data model, respectively
● {size_of_double} is either f for 32 bits or d for 64 bits.
CHARACTER-BASED I/O
The functions putchar and getchar are the fundamental C functions for
character-based I/O. For any character-based I/O to be available, you must provide
definitions for these two functions, using whatever facilities the hardware environment
provides.
AFE1_AFE2-1:1
The CLIB runtime environment
The code example below shows how memory-mapped I/O could be used to write to a
memory-mapped I/O device:
__no_init volatile unsigned char devIO @ 8;
The exact address is a design decision. For example, it can depend on the selected
processor variant.
For information about how to include your own modified version of putchar and
getchar in your project build process, see Overriding library modules, page 123.
By default, the linker automatically uses the most appropriate formatter for your
application.
_large_write
The _large_write formatter supports the C89 printf format directives.
_medium_write
The _medium_write formatter has the same format directives as _large_write,
except that floating-point numbers are not supported. Any attempt to use a %f, %g, %G,
%e, or %E specifier will produce a runtime error:
163
AFE1_AFE2-1:1
Input and output
_small_write
The _small_write formatter works in the same way as _medium_write, except that
it supports only the %%, %d, %o, %c, %s, and %x specifiers for integer objects, and does
not support field width or precision arguments. The size of _small_write is 10–15%
that of _medium_write.
Customizing printf
For many embedded applications, sprintf is not required, and even printf with
_small_write provides more facilities than are justified, considering the amount of
memory it consumes. Alternatively, a custom output routine might be required to
support particular formatting needs or non-standard output devices.
For such applications, a much reduced version of the printf function (without
sprintf) is supplied in source form in the file intwri.c. This file can be modified to
meet your requirements, and the compiled module inserted into the library in place of
the original file, see Overriding library modules, page 123.
By default, the linker automatically uses the most appropriate formatter for your
application.
AFE1_AFE2-1:1
The CLIB runtime environment
_large_read
The _large_read formatter supports the C89 scanf format directives.
_medium_read
The _medium_read formatter has the same format directives as the large version,
except that floating-point numbers are not supported. _medium_read is considerably
smaller than the large version.
Note: Normally, you do not need to customize either of the files cstartup.s43 or
cexit.s43.
SYSTEM STARTUP
When an application is initialized, several steps are performed:
● If MPU support is included, the function __iar_430_mpu_init is called to
initialize the MPU.
● The custom function __low_level_init is called if you defined it, giving the
application a chance to perform early initializations.
● Static variables are initialized; this includes clearing zero-initialized memory and
copying the ROM image of the RAM memory of the remaining initialized variables.
165
AFE1_AFE2-1:1
Overriding default library modules
SYSTEM TERMINATION
An application can terminate normally in two different ways:
● Return from the main function
● Call the exit function.
Because the C standard states that the two methods should be equivalent, the cstartup
code calls the exit function if main returns. The parameter passed to the exit function
is the return value of main. The default exit function is written in assembler.
When the application is built in debug mode, C-SPY stops when it reaches the special
code label ?C_EXIT.
An application can also exit by calling the abort function. The default function just
calls __exit to halt the system, without performing any type of cleanup.
AFE1_AFE2-1:1
The CLIB runtime environment
TERMINATION
The debugger stops executing when it reaches the special label ?C_EXIT.
MPU/IPE support
Some MSP430 devices support Memory Protection Unit (MPU) and Intellectual
Property Encapsulation, see MPU/IPE support, page 152.
167
AFE1_AFE2-1:1
MPU/IPE support
AFE1_AFE2-1:1
Assembler language
interface
● Mixing C and assembler
● Calling convention
INTRINSIC FUNCTIONS
The compiler provides a few predefined functions that allow direct access to low-level
processor operations without having to use the assembler language. These functions are
known as intrinsic functions. They can be useful in, for example, time-critical routines.
An intrinsic function looks like a normal function call, but it is really a built-in function
that the compiler recognizes. The intrinsic functions compile into inline code, either as
a single instruction, or as a short sequence of instructions.
The advantage of an intrinsic function compared to using inline assembler is that the
compiler has all necessary information to interface the sequence properly with register
169
AFE1_AFE2-1:1
Mixing C and assembler
allocation and variables. The compiler also knows how to optimize functions with such
sequences; something the compiler is unable to do with inline assembler sequences. The
result is that you get the desired sequence properly integrated in your code, and that the
compiler can optimize the result.
For more information about the available intrinsic functions, see the chapter Intrinsic
functions.
AFE1_AFE2-1:1
Assembler language interface
The recommended method for mixing C or C++ and assembler modules is described in
Calling assembler routines from C, page 178, and Calling assembler routines from
C++, page 180, respectively.
INLINE ASSEMBLER
Inline assembler can be used for inserting assembler instructions directly into a C or
C++ function. Typically, this can be useful if you need to:
● Access hardware resources that are not accessible in C (in other words, when there
is no definition for an SFR or there is no suitable intrinsic function available).
● Manually write a time-critical sequence of code that if written in C will not have the
right timing.
● Manually write a speed-critical sequence of code that if written in C will be too
slow.
● Call functions using a non-standard calling convention.
An inline assembler statement is similar to a C function in that it can take input
arguments (input operands), have return values (output operands), and read or write to
C symbols (via the operands). An inline assembler statement can also declare clobbered
resources (that is, values in registers and memory that have been overwritten).
Limitations
Most things you can to do in normal assembler language are also possible with inline
assembler, with the following differences:
● In general, assembler directives will cause errors or have no meaning. However,
data definition directives will work as expected.
● Resources used (registers, memory, etc) that are also used by the C compiler must
be declared as operands or clobbered resources.
● If you do not want to risk that the inline assembler statement to be optimized away
by the compiler, you must declare it volatile.
● Accessing a C symbol or using a constant expression requires the use of operands.
● Dependencies between the expressions for the operands might result in an error.
171
AFE1_AFE2-1:1
Mixing C and assembler
future. There are also several limitations to using inline assembler without operands and
clobbered resources:
● The inline assembler statement will be volatile and clobbered memory is not
implied. This means that the compiler will not remove the assembler statement. It
will simply be inserted at the given location in the program flow. The consequences
or side-effects that the insertion might have on the surrounding code are not taken
into consideration. If, for example, registers or memory locations are altered, they
might have to be restored within the sequence of inline assembler instructions for
the rest of the code to work properly.
The following example demonstrates the risks of using the asm keyword without
operands and clobbers:
int Add(int term1, int term2)
{
asm("add.w R13, R12");
return term1;
}
In this example:
● The function Add assumes that values are passed and returned in registers in a way
that they might not always be, for example if the function is inlined.
● The ADD instruction updates the condition flags, which you specify using the cc
clobber operand. Otherwise, the compiler will assume that the condition flags are
not modified.
Inline assembler without using operands or clobbered resources is therefore often best
avoided.
Syntax The syntax of an inline assembler statement is (similar to the one used by GNU gcc):
asm [volatile]( string [assembler-interface])
string can contain one or more valid assembler instructions or data definition
assembler directives, separated by \n.
AFE1_AFE2-1:1
Assembler language interface
For example:
void LoopForever(void)
{
asm("label: nop\n"
" jmp label");
}
Note that any labels you define in the inline assembler statement will be local to that
statement. You can use this for loops or conditional code.
If you define a label in an inline assembler statement using two colons (for example:
"label:: nop\n") instead of one, the label will be public, not only in the inline
assembler statement, but in the module as well. This feature is intended for testing only.
assembler-interface is:
: comma-separated list of output operands /* optional */
: comma-separated list of input operands /* optional */
: comma-separated list of clobbered resources /* optional */
Operands An inline assembler statement can have one input and one output comma-separated list
of operands. Each operand consists of an optional symbolic name in brackets, a quoted
constraint, followed by a C expression in parentheses.
For example:
int Add(int term1, int term2)
{
int sum;
asm("mov %1,%0\n"
"add %2,%0"
: "=r"(sum)
: "r"(term1), "r"(term2));
return sum;
}
In this example, the assembler instruction uses one output operand, sum, two input
operands, term1 and term2, and no clobbered resources.
173
AFE1_AFE2-1:1
Mixing C and assembler
Operand constraints
Constraint Description
r Uses a general purpose register or group of registers
R4-R15 A specific general purpose register or group of registers
i Integer constant (not valid as output)
m Operand referring to a memory location
digit The input must be in the same location as the output operand digit.
The first output operand is 0, the second 1, etc. (Not valid as output)
Table 21: Inline assembler operand constraints
Constraint modifiers Constraint modifiers can be used together with a constraint to modify its meaning. This
table lists the supported constraint modifiers:
Modifier Description
= Write-only operand
+ Read-write operand
& Early clobber output operand which is written to before the instruction
has processed all the input operands.
Table 22: Supported constraint modifiers
Referring to operands Assembler instructions refer to operands by prefixing their order number with %. The
first operand has order number 0 and is referred to by %0.
If the operand has a symbolic name, you can refer to it using the syntax
%[operand.name]. Symbolic operand names are in a separate namespace from C/C++
code and can be the same as a C/C++ variable names. Each operand name must however
be unique in each assembler statement.
AFE1_AFE2-1:1
Assembler language interface
For example:
int Add(int term1, int term2)
{
int sum;
Input operands Input operands cannot have any constraint modifiers, but they can have any valid C
expression as long as the type of the expression fits the register.
The C expression will be evaluated just before any of the assembler instructions in the
inline assembler statement and assigned to the constraint, for example a register.
Output operands Output operands must have = as a constraint modifier and the C expression must be an
l-value and specify a writable location. For example, =r for a write-only general purpose
register. The constraint will be assigned to the evaluated C expression (as an l-value)
immediately after the last assembler instruction in the inline assembler statement. Input
operands are assumed to be consumed before output is produced and the compiler may
use the same register for an input and output operand. To prohibit this, prefix the output
constraint with & to make it an early clobber resource, for example =&r. This will ensure
that the output operand will be allocated in a different register than the input operands.
Input/output operands An operand that should be used both for input and output must be listed as an output
operand and have the + modifier. The C expression must be an l-value and specify a
writable location. The location will be read immediately before any assembler
instructions and it will be written to right after the last assembler instruction.
This is an example of using a read-write operand:
int Double(int value)
{
asm("add.w %0,%0" : "+r"(value));
return value;
}
In the example above, the input value for value will be placed in a general purpose
register. After the assembler statement, the result from the ADD instruction will be placed
in the same register.
175
AFE1_AFE2-1:1
Mixing C and assembler
Clobbered resources An inline assembler statement can have a list of clobbered resources.
"resource1", "resource2", ...
Specify clobbered resources to inform the compiler about which resources the inline
assembler statement destroys. Any value that resides in a clobbered resource and that is
needed after the inline assembler statement will be reloaded.
Clobbered resources will not be used as input or output operands.
This is an example of how to use clobbered resources:
int Add(int term1, int term2)
{
int sum;
asm("mov %1,%0\n"
"add %2,%0"
: "=r"(sum)
: "r" (term1), "r" (term2)
: "cc");
return sum;
}
In this example the condition codes will be modified by the ADD instruction. Therefore,
"cc" must be listed in the clobber list.
Clobber Description
R4-R15 General purpose register
cc The condition flags (N, Z, V, and C)
memory To be used if the instructions modify any memory. This will avoid
keeping memory values cached in registers across the inline
assembler statement.
Table 23: List of valid clobbers
AFE1_AFE2-1:1
Assembler language interface
Operand modifiers An operand modifier is a single letter between the % and the operand number, which is
used for transforming the operand.
In the example below, the modifiers A and B are used for accessing the least and most
significant 16 bits, respectively, of the operands:
unsigned long Mov32(void)
{
unsigned long sum;
asm("mov.w %A1,%A0\n"
"mov.w %B1,%B0"
: "=r"(sum)
: "i"(0x12345678UL));
return sum;
}
Modifier Description
A The first (lowest) 16 bits of the operand.
B The second 16 bits of the operand.
C The third 16 bits of the operand. (64-bit types only)
D The fourth (highest) 16 bits of the operand. (64-bit types only)
Table 24: Operand modifiers and transformations
177
AFE1_AFE2-1:1
Calling assembler routines from C
One way of fulfilling these requirements is to create skeleton code in C, compile it, and
study the assembler list file.
int main()
{
int locInt = gInt;
gInt = Func(locInt, gChar);
return 0;
}
Note: In this example, we use a low optimization level when compiling the code to show
local and global variable access. If a higher level of optimization is used, the required
AFE1_AFE2-1:1
Assembler language interface
references to local variables could be removed during the optimization. The actual
function declaration is not changed by the optimization level.
The -lA option creates an assembler language output file including C or C++ source
lines as assembler comments. The . (period) specifies that the assembler file should be
named in the same way as the C or C++ module (skeleton), but with the filename
extension s43. The -On option means that no optimization will be used and -e enables
language extensions. In addition, make sure to use relevant compiler options, usually the
same as you use for other C or C++ source files in your project.
The result is the assembler source output file skeleton.s43.
Note: The -lA option creates a list file containing call frame information (CFI)
directives, which can be useful if you intend to study these directives and how they are
used. If you only want to study the calling convention, you can exclude the CFI
directives from the list file.
In the IDE, to exclude the CFI directives from the list file, choose
Project>Options>C/C++ Compiler>List and deselect the suboption Include call
frame information.
On the command line, to exclude the CFI directives from the list file, use the option -lB
instead of -lA.
Note: CFI information must be included in the source code to make the C-SPY Call
Stack window work.
179
AFE1_AFE2-1:1
Calling assembler routines from C++
In C++, data structures that only use C features are known as PODs (“plain old data
structures”), they use the same memory layout as in C. However, we do not recommend
that you access non-PODs from assembler routines.
The following example shows how to achieve the equivalent to a non-static member
function, which means that the implicit this pointer must be made explicit. It is also
possible to “wrap” the call to the assembler routine in a member function. Use an inline
AFE1_AFE2-1:1
Assembler language interface
member function to remove the overhead of the extra call—this assumes that function
inlining is enabled:
class MyClass;
extern "C"
{
void DoIt(MyClass *ptr, int arg);
}
class MyClass
{
public:
inline void DoIt(int arg)
{
::DoIt(this, arg);
}
};
Note: Support for C++ names from assembler code is extremely limited. This means
that:
● Assembler list files resulting from compiling C++ files cannot, in general, be passed
through the assembler.
● It is not possible to refer to or define C++ functions that do not have C linkage in
assembler.
Calling convention
A calling convention is the way a function in a program calls another function. The
compiler handles this automatically, but, if a function is written in assembler language,
you must know where and how its parameters can be found, how to return to the program
location from where it was called, and how to return the resulting value.
It is also important to know which registers an assembler-level routine must preserve. If
the program preserves too many registers, the program might be ineffective. If it
preserves too few registers, the result would be an incorrect program.
The compiler provides two calling conventions—Version1 and Version2. This section
describes the calling conventions used by the compiler. These items are examined:
● Choosing a calling convention
● Function declarations
● C and C++ linkage
● Preserved versus scratch registers
181
AFE1_AFE2-1:1
Calling convention
● Function entrance
● Function exit
● Return address handling
At the end of the section, some examples are shown to describe the calling convention
in practice.
New routines written in assembler should be declared using the function attribute
__cc_version2. This ensures that they will be called using the Version2 calling
convention if new calling conventions are introduced in future compilers.
The parameter value should have the same value as the one used internally by the
compiler. For information about what value to use, see the generated list file. If the
calling convention changes in future compiler versions, the runtime model value used
internally by the compiler will also change. Using this method gives a module
consistency check, because the linker produces errors for mismatches between the
values.
AFE1_AFE2-1:1
Assembler language interface
For more information about checking module consistency, see Checking module
consistency, page 111.
183
AFE1_AFE2-1:1
Calling convention
FUNCTION DECLARATIONS
In C, a function must be declared in order for the compiler to know how to call it. A
declaration could look as follows:
int MyFunction(int first, char * second);
This means that the function takes two parameters: an integer and a pointer to a
character. The function returns a value, an integer.
In the general case, this is the only knowledge that the compiler has about a function.
Therefore, it must be able to deduce the calling convention from this information.
It is often practical to share header files between C and C++. This is an example of a
declaration that declares a function with C linkage in both C and C++:
#ifdef __cplusplus
extern "C"
{
#endif
int F(int);
#ifdef __cplusplus
}
#endif
Scratch registers
Any function is permitted to destroy the contents of a scratch register. If a function needs
the register value after a call to another function, it must store it during the call, for
example on the stack.
AFE1_AFE2-1:1
Assembler language interface
Any of the registers R12 to R15 are considered scratch registers and can be used by the
function.
When the registers R11:R10:R9:R8 are used for passing a 64-bit scalar parameter, they
are also considered to be scratch registers.
Preserved registers
Preserved registers, on the other hand, are preserved across function calls. The called
function can use the register for other purposes, but must save the value before using the
register and restore it at the exit of the function.
The registers R4 to R11 are preserved registers.
If the registers R11:R10:R9:R8 are used for passing a 64-bit scalar parameter, they do
not have to be preserved.
Note: When compiling for the MSP430X architecture in the Small data model, only the
lower 16 bits of the registers are preserved, unless the __save_reg20 attribute is
specified. Because the code generated by the compiler in the Small data model does not
use the upper four bits of registers, it is only necessary to save and restore these bits if
they are used by any assembler routines.
Note: When compiling using the options --lock_r4 or --lock_r5, the R4 and R5
registers are not used.
FUNCTION ENTRANCE
Parameters can be passed to a function using one of these basic methods:
● In registers
● On the stack
It is much more efficient to use registers than to take a detour via memory, so the calling
convention is designed to use registers as much as possible. Only a limited number of
registers can be used for passing parameters; when no more registers are available, the
remaining parameters are passed on the stack. The parameters are also passed on the
stack in these cases:
● Structure types: struct, union, and classes
● Unnamed parameters to variable length (variadic) functions; in other words,
functions declared as foo(param1, ...), for example printf.
Note: Interrupt functions cannot take any parameters.
185
AFE1_AFE2-1:1
Calling convention
Hidden parameters
In addition to the parameters visible in a function declaration and definition, there can
be hidden parameters:
● If the function returns a structure, the memory location where to store the structure
is passed in the register R12 as a hidden parameter.
● If the function is a non-static C++ member function, then the this pointer is passed
as the first parameter (but placed after the return structure pointer, if there is one).
The reason for the requirement that the member function must be non-static is that
static member methods do not have a this pointer.
Register parameters
These registers are available for passing parameters:
Parameters Passed in registers, Version1 Passed in registers, Version2
8-bit values R12, R14 R12 to R15
16-bit values R12, R14 R12 to R15
20-bit values* R12, R14 R12 to R15
32-bit values (R13:R12), (R15:R14) (R13:R12), (R15:R14)
64-bit values (R15:R14:R13:R12), (R15:R14:R13:R12),
(R11:R10:R9:R8) (R11:R10:R9:R8)
Table 25: Registers used for passing parameters
* On MSP430X devices, if the Small data model is combined with the Large code
model, function pointers are passed as 32-bit values.
The assignment of registers to parameters is a straightforward process.
For Version1, the first parameter is assigned to R12 or R13:R12, depending on the size
of the parameter. The second parameter is passed in R14 or R15:R14. Should there be
no more available registers, the parameter is passed on the stack.
For Version2, each parameter is assigned to the first register that has not already been
assigned a parameter, starting from R12.
AFE1_AFE2-1:1
Assembler language interface
FUNCTION EXIT
A function can return a value to the function or program that called it, or it can have the
return type void.
The return value of a function, if any, can be scalar (such as integers and pointers),
floating-point, or a structure.
Note: An interrupt function must have the return type void.
* On MSP430X devices, if the Small data model is combined with the Large code
model, function pointers are returned as 32-bit values.
187
AFE1_AFE2-1:1
Calling convention
EXAMPLES
The following section shows a series of declaration examples and the corresponding
calling conventions. The complexity of the examples increases toward the end.
Example 1
Assume this function declaration:
int add1(int);
This function takes one parameter in the register R12, and the return value is passed back
to its caller in the register R12.
This assembler routine is compatible with the declaration; it will return a value that is
one number higher than the value of its parameter:
add.w #1,R12
ret
Example 2
This example shows how structures are passed on the stack. Assume these declarations:
struct MyStruct
{
short a;
short b;
short c;
short d;
short e;
};
The calling function must reserve 10 bytes on the top of the stack and copy the contents
of the struct to that location. The integer parameter y is passed in the register R12. The
return value is passed back to its caller in the register R12.
AFE1_AFE2-1:1
Assembler language interface
Example 3
The function below will return a structure of type struct MyStruct.
struct MyStruct
{
int mA[20];
};
It is the responsibility of the calling function to allocate a memory location for the return
value—typically on the stack—and pass a pointer to it as a hidden first parameter. The
pointer to the location where the return value should be stored is passed in R12. The
caller assumes that this register remains untouched. The parameter x is passed in R13.
Assume that the function instead was declared to return a pointer to the structure:
struct MyStruct *MyFunction(int x);
In this case, the return value is a pointer, so there is no hidden parameter. The parameter
x is passed in R12 and the return value is also returned in R12.
189
AFE1_AFE2-1:1
Assembler instructions used for calling functions
The return address is stored on the stack and uses 4 bytes of memory.
The return address is stored on the stack and uses 2 bytes of memory. It must be adjusted
before returning from the function:
add.w #0x4, 0(SP)
ret
The return address is stored on the stack and uses 4 bytes of memory. It must be adjusted
before returning from the function:
addx.a #0x4, 0(SP)
reta
INTERRUPT FUNCTIONS
Interrupt functions always return using the RETI instructions. This restores the status
registers and returns to the location where the interrupt occurred.
AFE1_AFE2-1:1
Assembler language interface
MODULE CONSISTENCY
When calling an assembler module from C modules, it is important to match the calling
convention.
Because the calling convention differs slightly between the two architectures, you can
define the runtime attribute __core in all your assembler routines, to avoid
inconsistency. Use one of the following lines:
RTMODEL "__core","430"
RTMODEL "__core","430X"
Also, for MSP430X devices, define the runtime attribute __code_model. Use one of:
RTMODEL "__code_model","small"
RTMODEL "__code_model","large"
Using these module consistency checks, the linker will produce an error if there is a
mismatch between the values.
For more information about checking module consistency, see Checking module
consistency, page 111.
191
AFE1_AFE2-1:1
Memory access methods
struct MyStruct
{
long mA;
char mB;
};
Examples
These examples access data16 memory in different ways:
mov.b &myVar,R14
mov.b MyArr(R12),R14
mov.b 0x4(R13),R14
AFE1_AFE2-1:1
Assembler language interface
Examples
These examples access data20 memory in different ways:
movx.b &myVar,R14
movx.b MyArr(R12),R14
mov.b 0x4(R13),R14
CFI DIRECTIVES
The CFI directives provide C-SPY with information about the state of the calling
function(s). Most important of this is the return address, and the value of the stack
pointer at the entry of the function or assembler routine. Given this information, C-SPY
can reconstruct the state for the calling function, and thereby unwind the stack.
A full description about the calling convention might require extensive call frame
information. In many cases, a more limited approach will suffice.
When describing the call frame information, the following three components must be
present:
● A names block describing the available resources to be tracked
● A common block corresponding to the calling convention
● A data block describing the changes that are performed on the call frame. This
typically includes information about when the stack pointer is changed, and when
permanent registers are stored or restored on the stack.
This table lists all the resources defined in the names block used by the compiler:
Resource Description
CFA The call frames of the stack
Table 27: Call frame information resources defined in a names block
193
AFE1_AFE2-1:1
Call frame information
Resource Description
R4–R15 Normal registers
R4L–R15L Lower 16 bits, when compiling for the MSP430X architecture
R4H–R15H Higher 4 bits, when compiling for the MSP430X architecture
SP The stack pointer
SR The processor state register
PC The program counter
Table 27: Call frame information resources defined in a names block (Continued)
2 Compile the C source code, and make sure to create a list file that contains call frame
information—the CFI directives.
On the command line, use the option -lA.
AFE1_AFE2-1:1
Assembler language interface
For the source code in this example, the list file looks like this:
NAME `Cfi`
RSEG CSTACK:DATA:SORT:NOROOT(0)
EXTERN ?longjmp_r4
EXTERN ?longjmp_r5
EXTERN ?setjmp_r4
EXTERN ?setjmp_r5
PUBWEAK ?setjmp_save_r4
PUBWEAK ?setjmp_save_r5
PUBLIC cfiExample
FUNCTION cfiExample,021203H
ARGFRAME CSTACK, 0, STACK
LOCFRAME CSTACK, 4, STACK
195
AFE1_AFE2-1:1
Call frame information
EXTERN F
FUNCTION F,0202H
RSEG CODE:CODE:REORDER:NOROOT(1)
cfiExample:
CFI Block cfiBlock0 Using cfiCommon0
CFI Function cfiExample
FUNCALL cfiExample, F
LOCFRAME CSTACK, 4, STACK
PUSH.W R10
CFI R10 Frame(CFA, -4)
CFI CFA SP+4
MOV.W R12, R10
MOV.W R10, R12
CALL #F
ADD.W R12, R10
MOV.W R10, R12
POP.W R10
CFI R10 SameValue
CFI CFA SP+2
RET
CFI EndBlock cfiBlock0
RSEG CODE:CODE:REORDER:NOROOT(1)
?setjmp_save_r4:
REQUIRE ?setjmp_r4
REQUIRE ?longjmp_r4
RSEG CODE:CODE:REORDER:NOROOT(1)
?setjmp_save_r5:
REQUIRE ?setjmp_r5
REQUIRE ?longjmp_r5
END
Note: The header file cfi.m43 contains the macros XCFI_NAMES and XCFI_COMMON,
which declare a typical names block and a typical common block. These two macros
declare several resources, both concrete and virtual.
AFE1_AFE2-1:1
Using C
● C language overview
● Extensions overview
C language overview
The IAR C/C++ Compiler for MSP430 supports the ISO/IEC 9899:1999 standard
(including up to technical corrigendum No.3), also known as C99. In this guide, this
standard is referred to as Standard C and is the default standard used in the compiler.
This standard is stricter than C89.
In addition, the compiler also supports the ISO 9899:1990 standard (including all
technical corrigenda and addenda), also known as C94, C90, C89, and ANSI C. In this
guide, this standard is referred to as C89. Use the --c89 compiler option to enable this
standard.
The C99 standard is derived from C89, but adds features like these:
● The inline keyword advises the compiler that the function defined immediately
after the keyword should be inlined
● Declarations and statements can be mixed within the same scope
● A declaration in the initialization expression of a for loop
● The bool data type
● The long long data type
● The complex floating-point type
● C++ style comments
● Compound literals
● Incomplete arrays at the end of structs
● Hexadecimal floating-point constants
● Designated initializers in structures and arrays
● The preprocessor operator _Pragma()
● Variadic macros, which are the preprocessor macro equivalents of printf style
functions
● VLA (variable length arrays) must be explicitly enabled with the compiler option
--vla
197
AFE1_AFE2-1:1
Extensions overview
● Inline assembler using the asm or the __asm keyword, see Inline assembler, page
171.
Note: Even though it is a C99 feature, the IAR C/C++ Compiler for MSP430 does not
support UCNs (universal character names).
Note: CLIB does not support any C99 functionality. For example, complex numbers and
variable length arrays are not supported.
Extensions overview
The compiler offers the features of Standard C and a wide set of extensions, ranging
from features specifically tailored for efficient programming in the embedded industry
to the relaxation of some minor standards issues.
This is an overview of the available extensions:
● IAR C language extensions
For information about available language extensions, see IAR C language extensions,
page 199. For more information about the extended keywords, see the chapter
Extended keywords. For information about C++, the two levels of support for the
language, and C++ language extensions, see the chapter Using C++.
● Pragma directives
The #pragma directive is defined by Standard C and is a mechanism for using
vendor-specific extensions in a controlled way to make sure that the source code is
still portable.
The compiler provides a set of predefined pragma directives, which can be used for
controlling the behavior of the compiler, for example, how it allocates memory,
whether it allows extended keywords, and whether it outputs warning messages.
Most pragma directives are preprocessed, which means that macros are substituted
in a pragma directive. The pragma directives are always enabled in the compiler. For
several of them there is also a corresponding C/C++ language extension. For
information about available pragma directives, see the chapter Pragma directives.
● Preprocessor extensions
The preprocessor of the compiler adheres to Standard C. The compiler also makes
several preprocessor-related extensions available to you. For more information, see
the chapter The preprocessor.
● Intrinsic functions
The intrinsic functions provide direct access to low-level processor operations and
can be useful in, for example, time-critical routines. The intrinsic functions compile
into inline code, either as a single instruction or as a short sequence of instructions.
For more information about using intrinsic functions, see Mixing C and assembler,
AFE1_AFE2-1:1
Using C
page 169. For information about available functions, see the chapter Intrinsic
functions.
● Library functions
The DLIB runtime environment provides the C and C++ library definitions in the
C/C++ standard library that apply to embedded systems. For more information, see
DLIB runtime environment—implementation details, page 379.
Note: Any use of these extensions, except for the pragma directives, makes your source
code inconsistent with Standard C.
199
AFE1_AFE2-1:1
IAR C language extensions
AFE1_AFE2-1:1
Using C
__segment_begin Returns the address of the first byte of the named segment.
__segment_end Returns the address of the first byte after the named segment.
__segment_size Returns the size of the named segment in bytes.
The operators can be used on named segments defined in the linker configuration file.
These operators behave syntactically as if declared like:
void * __segment_begin(char const * segment)
void * __segment_end(char const * segment)
size_t __segment_size(char const * segment)
When you use the @ operator or the #pragma location directive to place a data object
or a function in a user-defined segment in the linker configuration file, the segment
operators can be used for getting the start and end address of the memory range where
the segments were placed.
The named segment must be a string literal and it must have been declared earlier with
the #pragma segment directive. If the segment was declared with a memory attribute
memattr, the type of the __segment_begin operator is a pointer to memattr void.
Otherwise, the type is a default pointer to void. Note that you must enable language
extensions to use these operators.
Note: These segment operators always return the linked address of a segment. When
ROPI is used, you must add the code distance to get the actual address, see
__code_distance, page 358.
Example
In this example, the type of the __segment_begin operator is void __data16 *.
#pragma segment="MYSEGMENT" __data16
...
segment_start_address = __segment_begin("MYSEGMENT");
201
AFE1_AFE2-1:1
IAR C language extensions
RELAXATIONS TO STANDARD C
This section lists and briefly describes the relaxation of some Standard C issues and also
some useful but minor syntax extensions:
● Arrays of incomplete types
An array can have an incomplete struct, union, or enum type as its element type.
The types must be completed before the array is used (if it is), or by the end of the
compilation unit (if it is not).
● Forward declaration of enum types
The extensions allow you to first declare the name of an enum and later resolve it by
specifying the brace-enclosed list.
● Accepting missing semicolon at the end of a struct or union specifier
A warning—instead of an error—is issued if the semicolon at the end of a struct
or union specifier is missing.
● Null and void
In operations on pointers, a pointer to void is always implicitly converted to another
type if necessary, and a null pointer constant is always implicitly converted to a null
pointer of the right type if necessary. In Standard C, some operators allow this kind
of behavior, while others do not allow it.
● Casting pointers to integers in static initializers
In an initializer, a pointer constant value can be cast to an integral type if the integral
type is large enough to contain it. For more information about casting pointers, see
Casting, page 310.
● Taking the address of a register variable
In Standard C, it is illegal to take the address of a variable specified as a register
variable. The compiler allows this, but a warning is issued.
● long float means double
The type long float is accepted as a synonym for double.
● Repeated typedef declarations
Redeclarations of typedef that occur in the same scope are allowed, but a warning
is issued.
● Mixing pointer types
Assignment and pointer difference is allowed between pointers to types that are
interchangeable but not identical; for example, unsigned char * and char *. This
includes pointers to integral types of the same size. A warning is issued.
AFE1_AFE2-1:1
Using C
203
AFE1_AFE2-1:1
IAR C language extensions
return y;
}
● Expanding function names into strings with the function as context
Use any of the symbols __func__ or __FUNCTION__ inside a function body to
make the symbol expand into a string that contains the name of the current function.
Use the symbol __PRETTY_FUNCTION__ to also include the parameter types and
return type. The result might, for example, look like this if you use the
__PRETTY_FUNCTION__ symbol:
"void func(char)"
These symbols are useful for assertions and other trace utilities and they require that
language extensions are enabled, see -e, page 278.
● Static functions in function and block scopes
Static functions may be declared in function and block scopes. Their declarations are
moved to the file scope.
● Numbers scanned according to the syntax for numbers
Numbers are scanned according to the syntax for numbers rather than the
pp-number syntax. Thus, 0x123e+1 is scanned as three tokens instead of one valid
token. (If the --strict option is used, the pp-number syntax is used instead.)
AFE1_AFE2-1:1
Using C++
● Overview—EC++ and EEC++
EMBEDDED C++
These C++ features are supported:
● Classes, which are user-defined types that incorporate both data structure and
behavior; the essential feature of inheritance allows data structure and behavior to
be shared among classes
● Polymorphism, which means that an operation can behave differently on different
classes, is provided by virtual functions
● Overloading of operators and function names, which allows several operators or
functions with the same name, provided that their argument lists are sufficiently
different
● Type-safe memory management using the operators new and delete
● Inline functions, which are indicated as particularly suitable for inline expansion.
205
AFE1_AFE2-1:1
Overview—EC++ and EEC++
C++ features that are excluded are those that introduce overhead in execution time or
code size that are beyond the control of the programmer. Also excluded are features
added very late before Standard C++ was defined. Embedded C++ thus offers a subset
of C++ which is efficient and fully supported by existing development tools.
Embedded C++ lacks these features of C++:
● Templates
● Multiple and virtual inheritance
● Exception handling
● Runtime type information
● New cast syntax (the operators dynamic_cast, static_cast,
reinterpret_cast, and const_cast)
● Namespaces
● The mutable attribute.
The exclusion of these language features makes the runtime library significantly more
efficient. The Embedded C++ library furthermore differs from the full C++ library in
that:
● The standard template library (STL) is excluded
● Streams, strings, and complex numbers are supported without the use of templates
● Library features which relate to exception handling and runtime type information
(the headers except, stdexcept, and typeinfo) are excluded.
Note: The library is not in the std namespace, because Embedded C++ does not
support namespaces.
AFE1_AFE2-1:1
Using C++
language, which means no exceptions and no support for runtime type information
(rtti). Moreover, the library is not in the std namespace.
Note: A module compiled with Extended EC++ enabled is fully link-compatible with a
module compiled without Extended EC++ enabled.
For EC++, and EEC++, you must also use the IAR DLIB runtime library.
To enable EC++ or EEC++ in the IDE, choose Project>Options>C/C++
Compiler>Language 1 and select the appropriate standard.
207
AFE1_AFE2-1:1
EC++ feature descriptions
// A task function
__task void G();
Class memory
To compensate for this limitation, a class can be associated with a class memory type.
The class memory type changes:
● the this pointer type in all member functions, constructors, and destructors into a
pointer to class memory
● the default memory for static storage duration variables—that is, not auto
variables—of the class type, into the specified class memory
● the pointer type used for pointing to objects of the class type, into a pointer to class
memory.
AFE1_AFE2-1:1
Using C++
Example
class __data20 C
{
public:
void MyF(); // Has a this pointer of type C __data20 *
void MyF() const; // Has a this pointer of type
// C __data20 const *
C(); // Has a this pointer pointing into data20
// memory
C(C const &); // Takes a parameter of type C __data20
// const & (also true of generated copy
// constructor)
int mI;
};
Whenever a class type associated with a class memory type, like C, must be declared,
the class memory type must be mentioned as well:
class __data20 C;
Also note that class types associated with different class memories are not compatible
types.
A built-in operator returns the class memory type associated with a class,
__memory_of(class). For instance, __memory_of(C) returns __data20.
When inheriting, the rule is that it must be possible to convert implicitly a pointer to a
subclass into a pointer to its base class. This means that a subclass can have a more
restrictive class memory than its base class, but not a less restrictive class memory.
209
AFE1_AFE2-1:1
EC++ feature descriptions
class F : public C
{ // OK, will be associated with same class memory as C
public:
void MyG();
int mJ;
};
Note that the following is not allowed because data20 is not inside data16memory:
class __data20 G:public C
{
};
A new expression on the class will allocate memory in the heap associated with the class
memory. A delete expression will naturally deallocate the memory back to the same
heap. To override the default new and delete operator for a class, declare
void *operator new(size_t);
void operator delete(void *);
FUNCTION TYPES
A function type with extern "C" linkage is compatible with a function that has C++
linkage.
AFE1_AFE2-1:1
Using C++
Example
extern "C"
{
typedef void (*FpC)(void); // A C function typedef
}
FpC F1;
FpCpp F2;
void MyF(FpC);
void MyG()
{
MyF(F1); // Always works
MyF(F2); // FpCpp is compatible with FpC
}
Use this syntax if you want to override both global and class-specific operator new
and operator delete for any data memory.
Note that there is a special syntax to name the operator new functions for each
memory, while the naming for the operator delete functions relies on normal
overloading.
211
AFE1_AFE2-1:1
EC++ feature descriptions
Note that the pointer used in a delete expression must have the correct type, that is, the
same type as that returned by the new expression. If you use a pointer to the wrong
memory, the result might be a corrupt heap.
AFE1_AFE2-1:1
Using C++
Function local static class objects are constructed the first time execution passes through
their declaration, and are destroyed when returning from main or when calling exit.
TEMPLATES
Extended EC++ supports templates according to the C++ standard, but not the export
keyword. The implementation uses a two-phase lookup which means that the keyword
typename must be inserted wherever needed. Furthermore, at each use of a template,
the definitions of all possible templates must be visible. This means that the definitions
of all templates must be in include files or in the actual source file.
213
AFE1_AFE2-1:1
EEC++ feature description
TEMPLATES
The compiler supports templates with the syntax and semantics as defined by Standard
C++. However, note that the STL (standard template library) delivered with the product
is tailored for Extended EC++, see Extended Embedded C++, page 206.
Example
// We assume that __data20 is the memory type of the default
// pointer.
template<typename> class Z {};
template<typename T> class Z<T *> {};
AFE1_AFE2-1:1
Using C++
Example
// We assume that __data20 is the memory type of the default
// pointer.
template<typename T> void fun(T *);
void MyF()
{
fun((int __data16 *) 0); // T = int. The result is different
// than the analogous situation with
// class template specializations.
fun((int *) 0); // T = int
fun((int __data20 *) 0); // T = int
}
For templates that are matched using this modified algorithm, it is impossible to get
automatic generation of special code for pointers to “small” memory types. For “large”
and “other” memory types (memory that cannot be pointed to by a default pointer) it is
possible. To make it possible to write templates that are fully memory-aware—in the
rare cases where this is useful—use the #pragma basic_template_matching
directive in front of the template function declaration. That template function will then
match without the modifications described above.
Example
// We assume that __data20 is the memory type of the default
// pointer.
#pragma basic_template_matching
template<typename T> void fun(T *);
void MyF()
{
fun((int __data16 *) 0); // T = int __data16
}
215
AFE1_AFE2-1:1
EEC++ feature description
Example
#include <intrinsics.h>
void bar()
{
foo<x>();
}
Note: This example must be compiled with the --regvar_r4 compiler option.
Example
#include <vector>
AFE1_AFE2-1:1
Using C++
Example
#include <vector>
Note also that map<key, T>, multimap<key, T>, hash_map<key, T>, and
hash_multimap<key, T> all use the memory of T. This means that the value_type
of these collections will be pair<key, const T> mem where mem is the memory type
of T. Supplying a key with a memory type is not useful.
Example
Note that two containers that only differ by the data memory attribute they use cannot
be assigned to each other. Instead, the templated assign member method must be used.
#include <vector>
vector<int __data16> X;
vector<int __data20> Y;
void MyF()
{
// The templated assign member method will work
X.assign(Y.begin(), Y.end());
Y.assign(X.begin(), X.end());
}
217
AFE1_AFE2-1:1
C++ language extensions
MUTABLE
The mutable attribute is supported in Extended EC++. A mutable symbol can be
changed even though the whole class object is const.
NAMESPACE
The namespace feature is only supported in Extended EC++. This means that you can
use namespaces to partition your code. Note, however, that the library itself is not placed
in the std namespace.
You must make sure that identifiers in your application do not interfere with identifiers
in the runtime library.
AFE1_AFE2-1:1
Using C++
● In the declaration of a class member, a qualified name can be used, for example:
struct A
{
int A::F(); // Possible when using IAR language extensions
int G(); // According to the standard
};
● It is permitted to use an implicit type conversion between a pointer to a function
with C linkage (extern "C") and a pointer to a function with C++ linkage
(extern "C++"), for example:
extern "C" void F(); // Function with C linkage
void (*PF)() // PF points to a function with C++ linkage
= &F; // Implicit conversion of function pointer.
According to the standard, the pointer must be explicitly converted.
● If the second or third operands in a construction that contains the ? operator are
string literals or wide string literals (which in C++ are constants), the operands can
be implicitly converted to char * or wchar_t *, for example:
bool X;
class A
{
public:
U; // OK -- references to A::i and A::j are allowed.
};
In addition, this extension also permits anonymous classes and anonymous structs,
as long as they have no C++ features (for example, no static data members or member
219
AFE1_AFE2-1:1
C++ language extensions
functions, and no non-public members) and have no nested types other than other
anonymous classes, structs, or unions. For example:
struct A
{
struct
{
int i,j;
}; // OK -- references to A::i and A::j are allowed.
};
● The friend class syntax allows nonclass types as well as class types expressed
through a typedef without an elaborated type name. For example:
typedef struct S ST;
class C
{
public:
friend S; // Okay (requires S to be in scope)
friend ST; // Okay (same as "friend S;")
// friend S const; // Error, cv-qualifiers cannot
// appear directly
};
● It is allowed to specify an array with no size or size 0 as the last member of a struct.
For example:
typedef struct
{
int i;
char ir[0]; // Zero-length array
};
typedef struct
{
int i;
char ir[]; // Zero-length array
};
Note: If you use any of these constructions without first enabling language extensions,
errors are issued.
AFE1_AFE2-1:1
Application-related
considerations
● Stack considerations
● Heap considerations
Stack considerations
To make your application use stack memory efficiently, there are some considerations
to be made.
Heap considerations
The heap contains dynamic data allocated by use of the C function malloc (or a
corresponding function) or the C++ operator new.
If your application uses dynamic memory allocation, you should be familiar with:
● Linker segments used for the heap
221
AFE1_AFE2-1:1
Heap considerations
● Allocating the heap size, see Setting up heap memory, page 106.
If you use any of the standard functions without a prefix, the function will be mapped to
the default memory type data16.
Each heap will reside in a segment with the name _HEAP prefixed by a memory attribute,
for example DATA16_HEAP.
For information about available heaps, see Dynamic memory on the heap, page 69.
AFE1_AFE2-1:1
Application-related considerations
In this example, the function GetElementArray() allocates an array. The size of the
array is controlled by the linker. Add -DNrOfElements=100 to the linker configuration
file:
#include <stdlib.h>
Here, MyHeap() returns a pointer to a cleared memory area. The size and placement of
the memory area is controlled by the linker. Add the following lines to the linker
configuration file, and adapt the range to your device:
-DHeapSize=40
-Z(DATA)MYHEAP+HeapSize=4000-FFFF
223
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
char *MyHeap()
{
/* First get start of statically allocated section, */
char *p = __segment_begin("MYHEAP");
AFE1_AFE2-1:1
Application-related considerations
● You must add specific code to your application source code for comparing the two
checksums and take an appropriate action if they differ.
If the two checksums have been calculated in the same way, and if there are no errors
in the image, the checksums should be identical. If not, you should first suspect that
the two checksums were not generated in the same way.
No matter which solutions you use for generating the two checksum, you must make
sure that both checksums are calculated in the exact same way. If you use the linker for
the initial checksum and use a software-based calculation during runtime, you have full
control of the generation for both checksums. However, if you are using a third-party
checksum for the initial checksum or some hardware support for the checksum
calculation during runtime, there might be additional requirements that you must
consider.
For the two checksums, there are some choices that you must always consider and there
are some choices to make only if there are additional requirements. Still, all of the details
must be the same for both checksums.
Always consider:
● Checksum range
The memory range (or ranges) that you want to verify by means of checksums.
Typically, you might want to calculate a checksum for all ROM memory. However,
you might want to calculate a checksum only for specific ranges. Remember that:
● It is OK to have several ranges for one checksum.
● Typically, the checksum must be calculated from the lowest to the highest
address for every memory range.
● Each memory range must be verified in the same order as defined, for example,
0x100–0x1FF,0x400–0x4FF is not the same as 0x400–0x4FF,0x100–0x1FF.
● If several checksums are used, you should place them in sections with unique
names and use unique symbol names.
● A checksum should never be calculated on a memory range that contains a
checksum or a software breakpoint.
● Algorithm and size of checksum
You should consider which algorithm is most suitable in your case. There are two
basic choices, Sum—a simple arithmetic algorithm—or CRC—which is the most
commonly used algorithm. For CRC there are different sizes to choose for the
checksum, 2 or 4 bytes where the predefined polynomials are wide enough to suit the
size, for more error detecting power. The predefined polynomials work well for most,
but possibly not for all data sets. If not, you can specify your own polynomial. If you
just want a decent error detecting mechanism, use the predefined CRC algorithm for
your checksum size, typically CRC16 or CRC32.
225
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
Note: For an n-bit polynomial, the n:th bit is always considered to be set. For a 16-bit
polynomial—for example, CRC16—this means that 0x11021 is the same as
0x1021.
For more information about selecting an appropriate polynomial for data sets with
non-uniform distribution, see for example section 3.5.3 in Tannenbaum, A.S.,
Computer Networks, Prentice Hall 1981, ISBN: 0131646990.
● Fill
Every byte in the checksum range must have a well-defined value before the
checksum can be calculated. Typically, bytes with unknown values are pad bytes that
have been added for alignment. This means that you must specify which fill pattern
to be used during calculation, typically 0xFF or 0x00.
● Initial value
The checksum must always have an explicit initial value.
In addition to these mandatory details, there might be other details to consider.
Typically, this might happen when you have a third-party checksum, you want the
checksum be compliant with the Rocksoft™ checksum model, or when you use
hardware support for generating a checksum during runtime. The linker also provides
support for controlling alignment, complement, bit order, and checksum unit size.
AFE1_AFE2-1:1
Application-related considerations
For more information, see Briefly about checksum calculation, page 224.
To run the linker from the IDE, choose Project>Options>Linker>Checksum and
make your settings, for example:
In the simplest case, you can ignore (or leave with default settings) these options:
Complement, Bit order, and Checksum unit size.
To make the linker create a checksum from the command line, use the -J linker option,
for example like this:
-J2,crc16,,__checksum,CHECKSUM,1=0x8002–0x8FFF
The checksum will be created when you build your project and will be placed in the
automatically generated segment CHECKSUM. If you are using your own linker
configuration file or if you explicitly want to control the placement of the CHECKSUM
segment, you must update your linker configuration file with placement information
accordingly. In that case, make sure to place the segment so that it is not part of the
application’s checksum calculation.
3 You can specify several ranges instead of only one range.
If you are using the IDE, perform these steps:
● Choose Project>Options>Linker>Checksum and make sure to deselect Fill
unused code memory.
● Choose Project>Options>Linker>Extra Options and specify the ranges, for
example like this:
-h(CODE)0-3FF,8002-8FFF
-J2,crc16,,,1=0-3FF,8002-8FFF
227
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
If you are using the command line, use the -J option and specify the ranges. for example
like this:
-h(CODE)0-3FF,8002-8FFF
-J2,crc16,,,1=0-3FF,8002-8FFF
AFE1_AFE2-1:1
Application-related considerations
4 Add a function for checksum calculation to your source code. Make sure that the
function uses the same algorithm and settings as for the checksum calculated by the
linker. For example, a slow variant of the crc16 algorithm but with small memory
footprint (in contrast to the fast variant that uses more memory):
unsigned short SmallCrc16(uint16_t
sum,
unsigned char *p,
unsigned int len)
{
while (len--)
{
int i;
unsigned char byte = *(p++);
You can find the source code for this checksum algorithm in the 430\src\linker
directory of your product installation.
5 Make sure that your application also contains a call to the function that calculates the
checksum, compares the two checksums, and takes appropriate action if the checksum
values do not match.
229
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
This code gives an example of how the checksum can be calculated for your application
and to be compared with the linker generated checksum:
/* The calculated checksum */
void TestChecksum()
{
unsigned short calc = 0;
unsigned char zeros[2] = {0, 0};
/* Checksum is correct */
}
AFE1_AFE2-1:1
Application-related considerations
231
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
AFE1_AFE2-1:1
Efficient coding for
embedded applications
● Selecting data types
FLOATING-POINT TYPES
Using floating-point types on a microprocessor without a math coprocessor is
inefficient, both in terms of code size and execution speed. Therefore, you should
consider replacing code that uses floating-point operations with code that uses integers,
because these are more efficient.
The compiler supports two floating-point formats—32 and 64 bits. The 32-bit
floating-point type float is more efficient in terms of code size and execution speed.
The 64-bit format double supports higher precision and larger numbers.
233
AFE1_AFE2-1:1
Selecting data types
In the compiler, the floating-point type float always uses the 32-bit format. The format
used by the double floating-point type depends on the setting of the --double
compiler option.
Unless the application requires the extra precision that 64-bit floating-point numbers
give, we recommend using 32-bit floating-point numbers instead. Also, consider
replacing code using floating-point operations with code using integers because these
are more efficient.
By default, a floating-point constant in the source code is treated as being of the type
double. This can cause innocent-looking expressions to be evaluated in double
precision. In the example below a is converted from a float to a double, the double
constant 1.0 is added and the result is converted back to a float:
double Test(float a)
{
return a + 1.0;
}
To treat a floating-point constant as a float rather than as a double, add the suffix f
to it, for example:
double Test(float a)
{
return a + 1.0f;
}
For more information about floating-point types, see Basic data types—floating-point
types, page 307.
AFE1_AFE2-1:1
Efficient coding for embedded applications
Alternatively, write your own customized functions for packing and unpacking
structures. This is a more portable way, which will not produce any more code apart
from your functions. The drawback is the need for two views on the structure data—
packed and unpacked.
For more information about the #pragma pack directive, see pack, page 347.
Use the -e compiler option to enable language extensions. See -e, page 278, for
additional information.
Example
In this example, the members in the anonymous union can be accessed, in function F,
without explicitly specifying the union name:
struct S
{
char mTag;
union
{
long mL;
float mF;
};
} St;
void F(void)
{
St.mL = 5;
}
235
AFE1_AFE2-1:1
Controlling data and function placement in memory
The member names must be unique in the surrounding scope. Having an anonymous
struct or union at file scope, as a global, external, or static variable is also allowed.
This could for instance be used for declaring I/O registers, as in this example:
__no_init volatile
union
{
unsigned char IOPORT;
struct
{
unsigned char way: 1;
unsigned char out: 1;
};
} @ 8;
This declares an I/O register byte IOPORT at address 8. The I/O register has 2 bits
declared, way and out. Note that both the inner structure and the outer union are
anonymous.
Anonymous structures and unions are implemented in terms of objects named after the
first field, with a prefix _A_ to place the name in the implementation part of the
namespace. In this example, the anonymous union will be implemented through an
object named _A_IOPORT.
AFE1_AFE2-1:1
Efficient coding for embedded applications
To place a variable at an absolute address, the argument to the @ operator and the
#pragma location directive should be a literal number, representing the actual
address. The absolute location must fulfill the alignment requirement for the variable
that should be located.
Note: All declarations of variables placed at an absolute address are tentative
definitions. Tentatively defined variables are only kept in the output from the compiler
if they are needed in the module being compiled. Such variables will be defined in all
modules in which they are used, which will work as long as they are defined in the same
way. The recommendation is to place all such declarations in header files that are
included in all modules that use the variables.
237
AFE1_AFE2-1:1
Controlling data and function placement in memory
Examples
In this example, a __no_init declared variable is placed at an absolute address. This
is useful for interfacing between multiple processes, applications, etc:
__no_init volatile char alpha @ 0x200;/* OK */
The next example contains two const declared objects. The first one is not initialized,
and the second one is initialized to a specific value. (The first case is useful for
configuration parameters, because they are accessible from an external interface.) Both
objects are placed in ROM. Note that in the second case, the compiler is not obliged to
actually read from the variable, because the value is known.
#pragma location=0x202
__no_init const int beta; /* OK */
In the first case, the value is not initialized by the compiler—the value must be set by
other means. The typical use is for configurations where the values are loaded to ROM
separately, or for special function registers that are read-only.
This shows incorrect usage:
int delta @ 0x206; /* Error, neither */
/* "__no_init" nor "const".*/
__no_init int epsilon @ 0x207; /* Error, misaligned. */
C++ considerations
In C++, module scoped const variables are static (module local), whereas in C they are
global. This means that each module that declares a certain const variable will contain
a separate variable with this name. If you link an application with several such modules
all containing (via a header file), for instance, the declaration:
volatile const __no_init int x @ 0x100; /* Bad in C++ */
the linker will report that more than one variable is located at address 0x100.
To avoid this problem and make the process the same in C and C++, you should declare
these variables extern, for example:
/* The extern keyword makes x public. */
extern volatile const __no_init int x @ 0x100;
Note: C++ static member variables can be placed at an absolute address just like any
other static variable.
AFE1_AFE2-1:1
Efficient coding for embedded applications
#pragma location="MY_CONSTANTS"
const int beta = 42; /* OK */
The compiler will warn that segments that contain zero-initialized and initialized data
must be handled manually. To do this, you must use the linker option -Q to separate the
initializers into one separate segment and the symbols to be initialized to a different
239
AFE1_AFE2-1:1
Controlling compiler optimizations
segment. You must then write source code that copies the initializer segment to the
initialized segment, and zero-initialized symbols must be cleared before they are used.
As described elsewhere, for MSP430X you can use memory attributes to select a
memory for the variable. Note that you must as always ensure that the segment is placed
in the appropriate memory area when linking.
__data16 __no_init int alpha @ "MY_DATA16_NOINIT";/* Placed in
data16*/
#pragma location="MY_FUNCTIONS"
void h(void);
AFE1_AFE2-1:1
Efficient coding for embedded applications
241
AFE1_AFE2-1:1
Controlling compiler optimizations
OPTIMIZATION LEVELS
The compiler supports different levels of optimizations. This table lists optimizations
that are typically performed on each level:
Optimization level Description
None (Best debug support) Variables live through their entire scope
Dead code elimination
Redundant label elimination
Redundant branch elimination
Low Same as above but variables only live for as long as they are
needed, not necessarily through their entire scope
Medium Same as above, and:
Live-dead analysis and optimization
Code hoisting
Register content analysis and optimization
Common subexpression elimination
High (Balanced) Same as above, and:
Peephole optimization
Cross jumping
Loop unrolling
Function inlining
Type-based alias analysis
Table 29: Compiler optimization levels
Note: Some of the performed optimizations can be individually enabled or disabled. For
more information, see Fine-tuning enabled transformations, page 243.
A high level of optimization might result in increased compile time, and will also most
likely make debugging more difficult, because it is less clear how the generated code
relates to the source code. For example, at the low, medium, and high optimization
levels, variables do not live through their entire scope, which means processor registers
used for storing variables can be reused immediately after they were last used. Due to
this, the C-SPY Watch window might not be able to display the value of the variable
throughout its scope, or even occasionally display an incorrect value. At any time, if you
experience difficulties when debugging your code, try lowering the optimization level.
AFE1_AFE2-1:1
Efficient coding for embedded applications
If you use the optimization level High speed, the --no_size_constraints compiler
option relaxes the normal restrictions for code size expansion and enables more
aggressive optimizations.
You can choose an optimization goal for each module, or even individual functions,
using command line options and pragma directives (see -O, page 291 and optimize, page
346). For a small embedded application, this makes it possible to achieve acceptable
speed performance while minimizing the code size: Typically, only a few places in the
application need to be fast, such as the most frequently executed inner loops, or the
interrupt handlers.
Rather than compiling the whole application with High (Balanced) optimization, you
can use High (Size) in general, but override this to get High (Speed) optimization only
for those functions where the application needs to be fast.
Note: Because of the unpredictable way in which different optimizations interact, where
one optimization can enable other optimizations, sometimes a function becomes smaller
when compiled with High (Speed) optimization than if High (Size) is used. Also, using
multi-file compilation (see --mfc, page 284) can enable many optimizations to improve
both speed and size performance. It is recommended that you experiment with different
optimization settings so that you can pick the best ones for your project.
243
AFE1_AFE2-1:1
Controlling compiler optimizations
Loop unrolling
Loop unrolling means that the code body of a loop, whose number of iterations can be
determined at compile time, is duplicated. Loop unrolling reduces the loop overhead by
amortizing it over several iterations.
This optimization is most efficient for smaller loops, where the loop overhead can be a
substantial part of the total loop body.
Loop unrolling, which can be performed at optimization level High, normally reduces
execution time, but increases code size. The resulting code might also be difficult to
debug.
The compiler heuristically decides which loops to unroll. Only relatively small loops
where the loop overhead reduction is noticeable will be unrolled. Different heuristics are
used when optimizing for speed, size, or when balancing between size and speed.
Note: This option has no effect at optimization levels None, Low, and Medium.
To disable loop unrolling, use the command line option --no_unroll, see --no_unroll,
page 290.
Function inlining
Function inlining means that a function, whose definition is known at compile time, is
integrated into the body of its caller to eliminate the overhead of the call. This
optimization normally reduces execution time, but might increase the code size.
For more information, see Inlining functions, page 81.
To disable function inlining, use the command line option --no_inline, see
--no_inline, page 287.
Code motion
Evaluation of loop-invariant expressions and common subexpressions are moved to
avoid redundant re-evaluation. This optimization, which is performed at optimization
level Medium and above, normally reduces code size and execution time. The resulting
code might however be difficult to debug.
Note: This option has no effect at optimization levels below Medium.
For more information about the command line option, see --no_code_motion, page 286.
AFE1_AFE2-1:1
Efficient coding for embedded applications
because it is not necessarily known at compile time whether a particular value is being
changed.
Type-based alias analysis optimization assumes that all accesses to an object are
performed using its declared type or as a char type. This assumption lets the compiler
detect whether pointers can reference the same memory location or not.
Type-based alias analysis is performed at optimization level High. For application code
conforming to standard C or C++ application code, this optimization can reduce code
size and execution time. However, non-standard C or C++ code might result in the
compiler producing code that leads to unexpected behavior. Therefore, it is possible to
turn this optimization off.
Note: This option has no effect at optimization levels None, Low, and Medium.
For more information about the command line option, see --no_tbaa, page 289.
Example
short F(short *p1, long *p2)
{
*p2 = 0;
*p1 = 1;
return *p2;
}
With type-based alias analysis, it is assumed that a write access to the short pointed to
by p1 cannot affect the long value that p2 points to. Therefore, it is known at compile
time that this function returns 0. However, in non-standard-conforming C or C++ code
these pointers could overlap each other by being part of the same union. If you use
explicit casts, you can also force pointers of different pointer types to point to the same
memory location.
245
AFE1_AFE2-1:1
Facilitating good code generation
AFE1_AFE2-1:1
Efficient coding for embedded applications
FUNCTION PROTOTYPES
It is possible to declare and define functions using one of two different styles:
● Prototyped
● Kernighan & Ritchie C (K&R C)
Both styles are valid C, however it is strongly recommended to use the prototyped style,
and provide a prototype declaration for each public function in a header that is included
both in the compilation unit defining the function and in all compilation units using it.
The compiler will not perform type checking on parameters passed to functions declared
using K&R style. Using prototype declarations will also result in more efficient code in
some cases, as there is no need for type promotion for these functions.
To make the compiler require that all function definitions use the prototyped style, and
that all public functions have been declared before being defined, use the
Project>Options>C/C++ Compiler>Language 1>Require prototypes compiler
option (--require_prototypes).
Prototyped style
In prototyped function declarations, the type for each parameter must be specified.
int Test(char, int); /* Declaration */
247
AFE1_AFE2-1:1
Facilitating good code generation
Here, the test is always false. On the right hand side, 0x80 is 0x0080, and ~0x0080
becomes 0xFF7F. On the left hand side, c1 is an 8-bit unsigned character in the range
0–255, which can never be equal to 0xFF7F. Furthermore, it cannot be negative, which
means that the integral promoted value can never have the topmost 8 bits set.
AFE1_AFE2-1:1
Efficient coding for embedded applications
iodevice.h files
The header files named iodevice.h support C and C++. They define SFRs using
structs and unions, and provide access to individual bits through bitfields.
249
AFE1_AFE2-1:1
Facilitating good code generation
enum {
WDTIS0 = 0x0001,
WDTIS1 = 0x0002,
WDTSSEL = 0x0004,
WDTCNTCL = 0x0008,
WDTTMSEL = 0x0010,
WDTNMI = 0x0020,
WDTNMIES = 0x0040,
WDTHOLD = 0x0080
};
By including the appropriate header file in your source code, you make it possible to
access either the object or any individual bit (or bitfields) from C code as follows:
/* Object access */
WDTCTL = 0x1234;
/* Bitfield accesses */
WDTCTL_bit.WDTSSEL = 1;
If more than one bit must be written to a memory-mapped peripheral unit at the same
time, for instance to stop the watchdog timer, the defined bit constants can be used
instead, for example:
WDTCTL = WDTPW | WDTHOLD; /* Stop watchdog timer */
For information about the @ operator, see Placing located data, page 104.
AFE1_AFE2-1:1
Efficient coding for embedded applications
mspdevice.h files
The header files named mspdevice.h support C, C++, and assembler. They define
SFRs using primitive types, and provide access to individual bits through preprocessor
defines.
The following example is from msp430x14x.h:
/* Watchdog Timer Control */
__no_init volatile unsigned short WDTCTL @ 0x0120u;
By including the appropriate header file in your source code, you can access the object
as follows:
/* Object access */
WDTCTL = 0x1234;
/* Bitfield accesses */
WDTCTL |= WDTSSEL;
NON-INITIALIZED VARIABLES
Normally, the runtime environment will initialize all global and static variables when the
application is started.
The compiler supports the declaration of variables that will not be initialized, using the
__no_init type modifier. They can be specified either as a keyword or using the
#pragma object_attribute directive. The compiler places such variables in a
separate segment, according to the specified memory keyword. See the chapter Linking
overview for more information.
For __no_init, the const keyword implies that an object is read-only, rather than that
the object is stored in read-only memory. It is not possible to give a __no_init object
an initial value.
251
AFE1_AFE2-1:1
Facilitating good code generation
Variables declared using the __no_init keyword could, for example, be large input
buffers or mapped to special RAM that keeps its content even when the application is
turned off.
For more information, see __no_init, page 326.
Note: To use this keyword, language extensions must be enabled, see -e, page 278. For
more information, see object_attribute, page 345.
AFE1_AFE2-1:1
Part 2. Reference
information
This part of the IAR C/C++ Compiler User Guide for MSP430 contains these
chapters:
● Compiler options
● Data representation
● Extended keywords
● Pragma directives
● Intrinsic functions
● The preprocessor
● Segment reference
253
254
External interface details
● Invocation syntax
● Compiler output
● Diagnostics
Invocation syntax
You can use the compiler either from the IDE or from the command line. See the IDE
Project Management and Building Guide for information about using the compiler from
the IDE.
For example, when compiling the source file prog.c, use this command to generate an
object file with debug information:
icc430 prog.c --debug
The source file can be a C or C++ file, typically with the filename extension c or cpp,
respectively. If no filename extension is specified, the file to be compiled must have the
extension c.
Generally, the order of options on the command line, both relative to each other and to
the source filename, is not significant. There is, however, one exception: when you use
the -I option, the directories are searched in the same order as they are specified on the
command line.
If you run the compiler from the command line without any arguments, the compiler
version number and all available options including brief descriptions are directed to
stdout and displayed on the screen.
255
AFE1_AFE2-1:1
Include file search procedure
PASSING OPTIONS
There are three different ways of passing options to the compiler:
● Directly from the command line
Specify the options on the command line after the icc430 command, either before
or after the source filename, see Invocation syntax, page 255.
● Via environment variables
The compiler automatically appends the value of the environment variables to every
command line, see Environment variables, page 256.
● Via a text file, using the -f option, see -f, page 280.
For general guidelines for the option syntax, an options summary, and a detailed
description of each option, see the chapter Compiler options.
ENVIRONMENT VARIABLES
These environment variables can be used with the compiler:
Environment variable Description
C_INCLUDE Specifies directories to search for include files, for example:
C_INCLUDE=c:\my_programs\embedded workbench
.n\430\inc;c:\headers
QCC430 Specifies command line options, for example: QCC430=-lA
asm.lst
Table 30: Compiler environment variables
AFE1_AFE2-1:1
External interface details
3 The automatically set up library system include directories. See --clib, page 270,
--dlib, page 276, and --dlib_config, page 277.
● If the compiler encounters the name of an #include file in double quotes, for
example:
#include "vars.h"
it searches the directory of the source file in which the #include statement occurs,
and then performs the same sequence as for angle-bracketed filenames.
If there are nested #include files, the compiler starts searching the directory of the file
that was last included, iterating upwards for each included file, searching the source file
directory last. For example:
src.c in directory dir\src
#include "src.h"
...
src.h in directory dir\include
#include "config.h"
...
When dir\exe is the current directory, use this command for compilation:
icc430 ..\src\src.c -I..\include -I..\debugconfig
Then the following directories are searched in the order listed below for the file
config.h, which in this example is located in the dir\debugconfig directory:
Use angle brackets for standard header files, like stdio.h, and double quotes for files
that are part of your application.
Note: Both \ and / can be used as directory delimiters.
For more information, see Overview of the preprocessor, page 369.
257
AFE1_AFE2-1:1
Compiler output
Compiler output
The compiler can produce the following output:
● A linkable object file
The object files produced by the compiler use a proprietary format called UBROF,
which stands for Universal Binary Relocatable Object Format. By default, the object
file has the filename extension r43.
● Optional list files
Various kinds of list files can be specified using the compiler option -l, see -l, page
282. By default, these files will have the filename extension lst.
● Optional preprocessor output files
A preprocessor output file is produced when you use the --preprocess option. The
file will have the filename extension i, by default.
● Diagnostic messages
Diagnostic messages are directed to the standard error stream and displayed on the
screen, and printed in an optional list file. For more information about diagnostic
messages, see Diagnostics, page 259.
● Error return codes
These codes provide status information to the operating system which can be tested
in a batch file, see Error return codes, page 258.
● Size information
Information about the generated amount of bytes for functions and data for each
memory is directed to the standard output stream and displayed on the screen. Some
of the bytes might be reported as shared.
Shared objects are functions or data objects that are shared between modules. If any
of these occur in more than one module, only one copy is retained. For example, in
some cases inline functions are not inlined, which means that they are marked as
shared, because only one instance of each function will be included in the final
application. This mechanism is sometimes also used for compiler-generated code or
data not directly associated with a particular function or variable, and when only one
instance is required in the final application.
AFE1_AFE2-1:1
External interface details
Diagnostics
This section describes the format of the diagnostic messages and explains how
diagnostic messages are divided into different levels of severity.
MESSAGE FORMAT
All diagnostic messages are issued as complete, self-explanatory messages. A typical
diagnostic message from the compiler is produced in the form:
level[tag]: message filename linenumber
Diagnostic messages are displayed on the screen, as well as printed in the optional list
file.
Use the option --diagnostics_tables to list all possible compiler diagnostic
messages.
259
AFE1_AFE2-1:1
Diagnostics
SEVERITY LEVELS
The diagnostic messages are divided into different levels of severity:
Remark
A diagnostic message that is produced when the compiler finds a source code construct
that can possibly lead to erroneous behavior in the generated code. Remarks are by
default not issued, but can be enabled, see --remarks, page 296.
Warning
A diagnostic message that is produced when the compiler finds a potential programming
error or omission which is of concern, but which does not prevent completion of the
compilation. Warnings can be disabled by use of the command line option
--no_warnings, see --no_warnings, page 290.
Error
A diagnostic message that is produced when the compiler finds a construct which clearly
violates the C or C++ language rules, such that code cannot be produced. An error will
produce a non-zero exit code.
Fatal error
A diagnostic message produced when the compiler finds a condition that not only
prevents code generation, but also makes further processing of the source code pointless.
After the message is issued, compilation terminates. A fatal error will produce a
non-zero exit code.
INTERNAL ERROR
An internal error is a diagnostic message that signals that there was a serious and
unexpected failure due to a fault in the compiler. It is produced using this form:
Internal error: message
AFE1_AFE2-1:1
External interface details
261
AFE1_AFE2-1:1
Diagnostics
AFE1_AFE2-1:1
Compiler options
● Options syntax
Options syntax
Compiler options are parameters you can specify to change the default behavior of the
compiler. You can specify options from the command line—which is described in more
detail in this section—and from within the IDE.
See the online help system for information about the compiler options available in the
IDE and how to set them.
TYPES OF OPTIONS
There are two types of names for command line options, short names and long names.
Some options have both.
● A short option name consists of one character, and it can have parameters. You
specify it with a single dash, for example -e
● A long option name consists of one or several words joined by underscores, and it
can have parameters. You specify it with double dashes, for example
--char_is_signed.
For information about the different methods for passing options, see Passing options,
page 256.
263
AFE1_AFE2-1:1
Options syntax
For options with a long name and an optional parameter, any parameter should be
specified with a preceding equal sign (=), like this:
--example_option=value
For options with a long name and a mandatory parameter, the parameter can be specified
either with a preceding equal sign (=) or with a preceding space, for example:
--diagnostics_tables=MyDiagnostics.lst
or
--diagnostics_tables MyDiagnostics.lst
AFE1_AFE2-1:1
Compiler options
● For options that take a filename as the destination for output, the parameter can be
specified as a path without a specified filename. The compiler stores the output in
that directory, in a file with an extension according to the option. The filename will
be the same as the name of the compiled source file, unless a different name was
specified with the option -o, in which case that name is used. For example:
icc430 prog.c -l ..\listings\
The produced list file will have the default name ..\listings\prog.lst
● The current directory is specified with a period (.). For example:
icc430 prog.c -l .
● / can be used instead of \ as the directory delimiter.
● By specifying -, input files and output files can be redirected to the standard input
and output stream, respectively. For example:
icc430 prog.c -l -
Additional rules
These rules also apply:
● When an option takes a parameter, the parameter cannot start with a dash (-)
followed by another character. Instead, you can prefix the parameter with two
dashes—this example will create a list file called -r:
icc430 prog.c -l ---r
● For options that accept multiple arguments of the same type, the arguments can be
provided as a comma-separated list (without a space), for example:
--diag_warning=Be0001,Be0002
Alternatively, the option can be repeated for each argument, for example:
--diag_warning=Be0001
--diag_warning=Be0002
265
AFE1_AFE2-1:1
Summary of compiler options
AFE1_AFE2-1:1
Compiler options
267
AFE1_AFE2-1:1
Summary of compiler options
AFE1_AFE2-1:1
Compiler options
--c89
Syntax --c89
Description Use this option to enable the C89 C dialect instead of Standard C.
Note: This option is mandatory when the MISRA C checking is enabled.
269
AFE1_AFE2-1:1
Descriptions of compiler options
--char_is_signed
Syntax --char_is_signed
Description By default, the compiler interprets the plain char type as unsigned. Use this option to
make the compiler interpret the plain char type as signed instead. This can be useful
when you, for example, want to maintain compatibility with another compiler.
Note: The runtime library is compiled without the --char_is_signed option and
cannot be used with code that is compiled with this option.
Project>Options>C/C++ Compiler>Language 2>Plain ‘char’ is
--char_is_unsigned
Syntax --char_is_unsigned
Description Use this option to make the compiler interpret the plain char type as unsigned. This is
the default interpretation of the plain char type.
Project>Options>C/C++ Compiler>Language 2>Plain ‘char’ is
--clib
Syntax --clib
Description Use this option to use the system header files for the CLIB library; the compiler will
automatically locate the files and use them when compiling.
--code_model
Syntax --code_model={small|large}
Parameters
small Uses the Small code model
AFE1_AFE2-1:1
Compiler options
Description Use this option to select the code model, which controls which instruction sequences are
used for function calls and returns. If you do not select a code model, the compiler uses
the default code model. Note that all modules of your application must use the same
code model.
Note: This option is only available if --core is set to 430X.
--core
Syntax --core={430|430X}
Parameters
430 (default) For devices based on the MSP430 architecture
430X For devices based on the MSP430X architecture
Description Use this option to select the processor core for which the code will be generated. If you
do not use the option to specify a core, Note that all modules of your application must
use the same core.
Project>Options>General Options>Target>Device
-D
Syntax -D symbol[=value]
Parameters
symbol The name of the preprocessor symbol
value The value of the preprocessor symbol
Description Use this option to define a preprocessor symbol. If no value is specified, 1 is used. This
option can be used one or more times on the command line.
271
AFE1_AFE2-1:1
Descriptions of compiler options
The option -D has the same effect as a #define statement at the top of the source file:
-Dsymbol
is equivalent to:
#define symbol 1
--data_model
Syntax --data_model={small|medium|large}
Parameters
small (default) Uses the Small data model.
medium Uses the Medium data model.
large Uses the Large data model.
Description Use this option to select the data model, which controls the default placement of data
objects. If you do not select a data model, the compiler uses the default data model. Note
that all modules of your application must use the same data model.
Note: This option is only available if --core is set to 430X.
--debug, -r
Syntax --debug
-r
AFE1_AFE2-1:1
Compiler options
Description Use the --debug or -r option to make the compiler include information in the object
modules required by the IAR C-SPY® Debugger and other symbolic debuggers.
Note: Including debug information will make the object files larger than otherwise.
Project>Options>C/C++ Compiler>Output>Generate debug information
--dependencies
Syntax --dependencies[=[i|m|n][s]] {filename|directory|+}
Parameters
i (default) Lists only the names of files
m Lists in makefile style (multiple rules)
n Lists in makefile style (one rule)
s Suppresses system files
+ Gives the same output as -o, but with the filename extension d
See also Rules for specifying a filename or directory as parameters, page 264.
Description Use this option to make the compiler list the names of all source and header files opened
for input into a file with the default filename extension i.
If --dependencies=m is used, the output is in makefile style. For each input file, one
line containing a makefile dependency rule is produced. Each line consists of the name
of the object file, a colon, a space, and the name of an input file. For example:
foo.r43: c:\iar\product\include\stdio.h
foo.r43: d:\myproject\include\foo.h
273
AFE1_AFE2-1:1
Descriptions of compiler options
That is, in addition to producing an object file, the command also produces a
dependency file in makefile style—in this example, using the extension .d.
2 Include all the dependency files in the makefile using, for example:
-include $(sources:.c=.d)
Because of the dash (-) it works the first time, when the .d files do not yet exist.
This option is not available in the IDE.
--diag_error
Syntax --diag_error=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe117
Description Use this option to reclassify certain diagnostic messages as errors. An error indicates a
violation of the C or C++ language rules, of such severity that object code will not be
generated. The exit code will be non-zero. This option may be used more than once on
the command line.
Project>Options>C/C++ Compiler>Diagnostics>Treat these as errors
--diag_remark
Syntax --diag_remark=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe177
Description Use this option to reclassify certain diagnostic messages as remarks. A remark is the
least severe type of diagnostic message and indicates a source code construction that
may cause strange behavior in the generated code. This option may be used more than
once on the command line.
Note: By default, remarks are not displayed—use the --remarks option to display
them.
AFE1_AFE2-1:1
Compiler options
--diag_suppress
Syntax --diag_suppress=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe117
Description Use this option to suppress certain diagnostic messages. These messages will not be
displayed. This option may be used more than once on the command line.
Project>Options>C/C++ Compiler>Diagnostics>Suppress these diagnostics
--diag_warning
Syntax --diag_warning=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe826
Description Use this option to reclassify certain diagnostic messages as warnings. A warning
indicates an error or omission that is of concern, but which will not cause the compiler
to stop before compilation is completed. This option may be used more than once on the
command line.
Project>Options>C/C++ Compiler>Diagnostics>Treat these as warnings
--diagnostics_tables
Syntax --diagnostics_tables {filename|directory}
Parameters See Rules for specifying a filename or directory as parameters, page 264.
275
AFE1_AFE2-1:1
Descriptions of compiler options
Description Use this option to list all possible diagnostic messages to a named file. This can be
convenient, for example, if you have used a pragma directive to suppress or change the
severity level of any diagnostic messages, but forgot to document why.
Typically, this option cannot be given together with other options.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
--discard_unused_publics
Syntax --discard_unused_publics
Description Use this option to discard unused public functions and variables when compiling with
the --mfc compiler option.
Note: Do not use this option only on parts of the application, as necessary symbols
might be removed from the generated output. Use the object attribute __root to keep
symbols that are used from outside the compilation unit, for example, interrupt handlers.
If the symbol does not have the __root attribute and is defined in the library, the library
definition will be used instead.
See also --mfc, page 284 and Multi-file compilation units, page 241.
Project>Options>C/C++ Compiler>Discard unused publics
--dlib
Syntax --dlib
Description Use this option to use the system header files for the DLIB library—the compiler will
automatically locate the files and use them when compiling.
Note: The DLIB library is used by default: To use the CLIB library, use the --clib
option instead.
See also --dlib_config, page 277, --no_system_include, page 288, --system_include_dir, page
299, and --clib, page 270.
To set related options, choose:
Project>Options>General Options>Library Configuration
AFE1_AFE2-1:1
Compiler options
--dlib_config
Syntax --dlib_config filename.h|config
Parameters
filename A DLIB configuration header file, see Rules for specifying a
filename or directory as parameters, page 264.
config The default configuration file for the specified configuration
will be used. Choose between:
none, no configuration will be used
Description Use this option to specify which library configuration to use, either by specifying an
explicit file or by specifying a library configuration—in which case the default file for
that library configuration will be used. Make sure that you specify a configuration that
corresponds to the library you are using. If you do not specify this option, the default
library configuration file will be used.
All prebuilt runtime libraries are delivered with corresponding configuration files. You
can find the library object files in the directory 430\lib. For examples and information
about prebuilt runtime libraries, see Prebuilt runtime libraries, page 127.
If you build your own customized runtime library, you should also create a
corresponding customized library configuration file, which must be specified to the
compiler. For more information, see Customizing and building your own runtime
library, page 124.
Note: This option only applies to the IAR DLIB runtime environment.
To set related options, choose:
Project>Options>General Options>Library Configuration
--double
Syntax --double={32|64}
Parameters
32 (default) 32-bit doubles are used
64 64-bit doubles are used
277
AFE1_AFE2-1:1
Descriptions of compiler options
Description Use this option to select the precision used by the compiler for representing the
floating-point types double and long double. The compiler can use either 32-bit or
64-bit precision. By default, the compiler uses 32-bit precision.
-e
Syntax -e
Description In the command line version of the compiler, language extensions are disabled by
default. If you use language extensions such as extended keywords and anonymous
structs and unions in your source code, you must use this option to enable them.
Note: The -e option and the --strict option cannot be used at the same time.
--ec++
Syntax --ec++
Description In the compiler, the default language is C. If you use Embedded C++, you must use this
option to set the language the compiler uses to Embedded C++.
Project>Options>C/C++ Compiler>Language 1>C++
and
Project>Options>C/C++ Compiler>Language 1>C++ dialect>Embedded C++
AFE1_AFE2-1:1
Compiler options
--eec++
Syntax --eec++
Description In the compiler, the default language is C. If you take advantage of Extended Embedded
C++ features like namespaces or the standard template library in your source code, you
must use this option to set the language the compiler uses to Extended Embedded C++.
--enable_multibytes
Syntax --enable_multibytes
Description By default, multibyte characters cannot be used in C or C++ source code. Use this option
to make multibyte characters in the source code be interpreted according to the host
computer’s default setting for multibyte support.
Multibyte characters are allowed in C and C++ style comments, in string literals, and in
character constants. They are transferred untouched to the generated code.
Project>Options>C/C++ Compiler>Language 2>Enable multibyte support
--enable_restrict
Syntax --enable_restrict
Description Enables the Standard C keyword restrict. This option can be useful for improving
analysis precision during optimization.
To set this option, use Project>Options>C/C++ Compiler>Extra options
279
AFE1_AFE2-1:1
Descriptions of compiler options
--error_limit
Syntax --error_limit=n
Parameters
n The number of errors before the compiler stops the
compilation. n must be a positive integer. 0 indicates no
limit.
Description Use the --error_limit option to specify the number of errors allowed before the
compiler stops the compilation. By default, 100 errors are allowed.
This option is not available in the IDE.
-f
Syntax -f filename
Parameters See Rules for specifying a filename or directory as parameters, page 264.
Description Use this option to make the compiler read command line options from the named file,
with the default filename extension xcl.
In the command file, you format the items exactly as if they were on the command line
itself, except that you may use multiple lines, because the newline character acts just as
a space or tab character.
Both C and C++ style comments are allowed in the file. Double quotes behave in the
same way as in the Microsoft Windows command line environment.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
--guard_calls
Syntax --guard_calls
Description Use this option to enable guards for function static variable initialization. This option
should be used in a threaded C++ environment.
AFE1_AFE2-1:1
Compiler options
--header_context
Syntax --header_context
Description Occasionally, to find the cause of a problem it is necessary to know which header file
that was included from which source line. Use this option to list, for each diagnostic
message, not only the source position of the problem, but also the entire include stack at
that point.
This option is not available in the IDE.
--hw_workaround
Syntax --hw_workaround=[CPU6|nop_after_lpm|CPU40]
Parameters
CPU6 Workaround for hardware issue CPU6
nop_after_lpm Workaround for hardware issues CPU18, CPU19, CPU24,
CPU25, CPU27, and CPU29
CPU40 Workaround for hardware issue CPU40
Description Use this option to enable compiler workarounds for various hardware issues. Specify the
option multiple times if you need to enable more than one workaround.
See also For more information about the workarounds available for the different hardware issues,
see the release notes.
When you select a device in the IAR Embedded Workbench IDE, the relevant hardware
workarounds are enabled automatically.
Note: The workaround for hardware issue CPU6 is not enabled automatically. To set
this option for CPU6, use Project>Options>C/C++ Compiler>Extra Options.
281
AFE1_AFE2-1:1
Descriptions of compiler options
-I
Syntax -I path
Parameters
path The search path for #include files
Description Use this option to specify the search paths for #include files. This option can be used
more than once on the command line.
-l
Syntax -l[a|A|b|B|c|C|D][N][H] {filename|directory}
Parameters
a (default) Assembler list file
A Assembler list file with C or C++ source as comments
b Basic assembler list file. This file has the same contents as a
list file produced with -la, except that no extra
compiler-generated information (runtime model attributes,
call frame information, frame size information) is included *
B Basic assembler list file. This file has the same contents as a
list file produced with -lA, except that no extra compiler
generated information (runtime model attributes, call frame
information, frame size information) is included *
c C or C++ list file
C (default) C or C++ list file with assembler source as comments
D C or C++ list file with assembler source as comments, but
without instruction offsets and hexadecimal byte values
N No diagnostics in file
H Include source lines from header files in output. Without this
option, only source lines from the primary source file are
included
AFE1_AFE2-1:1
Compiler options
* This makes the list file less useful as input to the assembler, but more useful for reading
by a human.
See also Rules for specifying a filename or directory as parameters, page 264.
--library_module
Syntax --library_module
Description Use this option to make the compiler generate a library module rather than a program
module. A program module is always included during linking. A library module will
only be included if it is referenced in your program.
Project>Options>C/C++ Compiler>Output>Module type>Library Module
--lock_r4
Syntax --lock_R4
Description Use this option to exclude the register R4 from use by the compiler. This makes the
module linkable with both modules that use R4 as __regvar and modules that do not
define their R4 usage. Use this option if the R4 registers is used by another tool, for
example a ROM-monitor debugger.
Project>Options>C/C++ Compiler>Code>R4 utilization>Not used
--lock_r5
Syntax --lock_R5
Description Use this option to exclude the register R5 from use by the compiler. This makes the
module linkable with both modules that use R5 as __regvar and modules that do not
define their R5 usage. Use this option if the R5 registers is used by another tool, for
example a ROM-monitor debugger.
283
AFE1_AFE2-1:1
Descriptions of compiler options
--macro_positions_in_diagnostics
Syntax --macro_positions_in_diagnostics
Description Use this option to obtain position references inside macros in diagnostic messages. This
is useful for detecting incorrect source code constructs in macros.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
--mfc
Syntax --mfc
Description Use this option to enable multi-file compilation. This means that the compiler compiles
one or several source files specified on the command line as one unit, which enhances
interprocedural optimizations.
Note: The compiler will generate one object file per input source code file, where the
first object file contains all relevant data and the other ones are empty. If you want only
the first file to be produced, use the -o compiler option and specify a certain output file.
See also --discard_unused_publics, page 276, --output, -o, page 292, and Multi-file compilation
units, page 241.
Project>Options>C/C++ Compiler>Multi-file compilation
--migration_preprocessor_extensions
Syntax --migration_preprocessor_extensions
Description If you need to migrate code from an earlier IAR Systems C or C++ compiler, you might
want to use this option. Use this option to use the following in preprocessor expressions:
● Floating-point expressions
● Basic type names and sizeof
AFE1_AFE2-1:1
Compiler options
--module_name
Syntax --module_name=name
Parameters
name An explicit object module name
Description Normally, the internal name of the object module is the name of the source file, without
a directory name or extension. Use this option to specify an object module name
explicitly.
This option is useful when several modules have the same filename, because the
resulting duplicate module name would normally cause a linker error; for example,
when the source file is a temporary file generated by a preprocessor.
Project>Options>C/C++ Compiler>Output>Object module name
--multiplier
Syntax --multiplier[=[16|16s|32]]
Parameters
No parameter The 16-bit hardware multiplier
16 The 16-bit hardware multiplier (same as no parameter)
16s The extended 16-bit hardware multiplier used by some 2xx devices
32 The 32-bit hardware multiplier
Description Use this option to generate code that accesses the hardware multiplier. This will also
disable interrupts during hardware multiplier accesses.
285
AFE1_AFE2-1:1
Descriptions of compiler options
Note: You should also redirect library function calls to variants that use the hardware
multiplier, see Hardware multiplier support, page 151.
To set related options, choose:
Project>Options>General Options>Target>Device
and
Project>Options>General Options>Target>Hardware multiplier
--no_call_frame_info
Syntax --no_call_frame_info
Description Normally, the compiler always generates call frame information in the output, to enable
the debugger to display the call stack even in code from modules with no debug
information. Use this option to disable the generation of call frame information.
--no_code_motion
Syntax --no_code_motion
--no_cse
Syntax --no_cse
AFE1_AFE2-1:1
Compiler options
--no_inline
Syntax --no_inline
--no_path_in_file_macros
Syntax --no_path_in_file_macros
Description Use this option to exclude the path from the return value of the predefined preprocessor
symbols __FILE__ and __BASE_FILE__.
--no_rw_dynamic_init
Syntax --no_rw_dynamic_init
Description When the option --ropi is used, the actual addresses of constant variables are not
known until at runtime. Therefore, pointers to constant data cannot be initialized
statically. The compiler rewrites such static initializations to be dynamic where it is
possible. Use the --no_rw_dynamic_init option to make the compiler give an error
instead of rewriting the initializations.
This option has no effect if --ropi is not used.
See also --ropi, page 296 and Position-independent code and read-only data, page 80.
287
AFE1_AFE2-1:1
Descriptions of compiler options
--no_size_constraints
Syntax --no_size_constraints
Description Use this option to relax the normal restrictions for code size expansion when optimizing
for high speed.
Note: This option has no effect unless used with -Ohs.
--no_static_destruction
Syntax --no_static_destruction
Description Normally, the compiler emits code to destroy C++ static variables that require
destruction at program exit. Sometimes, such destruction is not needed.
Use this option to suppress the emission of such code.
--no_system_include
Syntax --no_system_include
Description By default, the compiler automatically locates the system include files. Use this option
to disable the automatic search for system include files. In this case, you might need to
set up the search path by using the -I compiler option.
See also --dlib, page 276, --dlib_config, page 277, and --system_include_dir, page 299.
Project>Options>C/C++ Compiler>Preprocessor>Ignore standard include
directories
AFE1_AFE2-1:1
Compiler options
--no_tbaa
Syntax --no_tbaa
--no_typedefs_in_diagnostics
Syntax --no_typedefs_in_diagnostics
Description Use this option to disable the use of typedef names in diagnostics. Normally, when a
type is mentioned in a message from the compiler, most commonly in a diagnostic
message of some kind, the typedef names that were used in the original declaration are
used whenever they make the resulting text shorter.
289
AFE1_AFE2-1:1
Descriptions of compiler options
--no_ubrof_messages
Syntax --no_ubrof_messages
Description Use this option to minimize the size of your application object file by excluding
messages from the UBROF files. The file size can decrease by up to 60%. Note that the
XLINK diagnostic messages will, however, be less useful when you use this option.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
--no_unroll
Syntax --no_unroll
--no_warnings
Syntax --no_warnings
Description By default, the compiler issues warning messages. Use this option to disable all warning
messages.
This option is not available in the IDE.
--no_wrap_diagnostics
Syntax --no_wrap_diagnostics
Description By default, long lines in diagnostic messages are broken into several lines to make the
message easier to read. Use this option to disable line wrapping of diagnostic messages.
This option is not available in the IDE.
AFE1_AFE2-1:1
Compiler options
-O
Syntax -O[n|l|m|h|hs|hz]
Parameters
n None* (Best debug support)
l (default) Low*
m Medium
h High, balanced
hs High, favoring speed
hz High, favoring size
*All optimizations performed at level Low will be performed also at None. The only
difference is that at level None, all non-static variables will live during their entire scope.
Description Use this option to set the optimization level to be used by the compiler when optimizing
the code. If no optimization option is specified, the optimization level Low is used by
default. If only -O is used without any parameter, the optimization level High balanced
is used.
A low level of optimization makes it relatively easy to follow the program flow in the
debugger, and, conversely, a high level of optimization makes it relatively hard.
--omit_types
Syntax --omit_types
Description By default, the compiler includes type information about variables and functions in the
object output. Use this option if you do not want the compiler to include this type
information in the output, which is useful when you build a library that should not
contain type information. The object file will then only contain type information that is
a part of a symbol’s name. This means that the linker cannot check symbol references
for type correctness.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
291
AFE1_AFE2-1:1
Descriptions of compiler options
--only_stdout
Syntax --only_stdout
Description Use this option to make the compiler use the standard output stream (stdout), and
messages that are normally directed to the error output stream (stderr).
This option is not available in the IDE.
--output, -o
Syntax --output {filename|directory}
-o {filename|directory}
Parameters See Rules for specifying a filename or directory as parameters, page 264.
Description By default, the object code output produced by the compiler is located in a file with the
same name as the source file, but with the extension r43. Use this option to explicitly
specify a different output filename for the object code output.
This option is not available in the IDE.
--pending_instantiations
Syntax --pending_instantiations number
Parameters
number An integer that specifies the limit, where 64 is default. If 0
is used, there is no limit.
Description Use this option to specify the maximum number of instantiations of a given C++
template that is allowed to be in process of being instantiated at a given time. This is
used for detecting recursive instantiations.
Project>Options>C/C++ Compiler>Extra Options
AFE1_AFE2-1:1
Compiler options
--predef_macros
Syntax --predef_macros {filename|directory}
Parameters See Rules for specifying a filename or directory as parameters, page 264.
Description Use this option to list all symbols defined by the compiler or on the command line.
(Symbols defined in the source code are not listed.) When using this option, make sure
to also use the same options as for the rest of your project.
If a filename is specified, the compiler stores the output in that file. If a directory is
specified, the compiler stores the output in that directory, in a file with the predef
filename extension.
Note: This option requires that you specify a source file on the command line.
This option is not available in the IDE.
--preinclude
Syntax --preinclude includefile
Parameters See Rules for specifying a filename or directory as parameters, page 264.
Description Use this option to make the compiler read the specified include file before it starts to
read the source file. This is useful if you want to change something in the source code
for the entire application, for instance if you want to define a new symbol.
Project>Options>C/C++ Compiler>Preprocessor>Preinclude file
--preprocess
Syntax --preprocess[=[c][n][l]] {filename|directory}
Parameters
c Preserve comments
n Preprocess only
l Generate #line directives
See also Rules for specifying a filename or directory as parameters, page 264.
293
AFE1_AFE2-1:1
Descriptions of compiler options
--public_equ
Syntax --public_equ symbol[=value]
Parameters
symbol The name of the assembler symbol to be defined
value An optional value of the defined assembler symbol
Description This option is equivalent to defining a label in assembler language using the EQU
directive and exporting it using the PUBLIC directive. This option can be used more than
once on the command line.
This option is not available in the IDE.
--reduce_stack_usage
Syntax --reduce_stack_usage
Description Use this option to make the compiler minimize the use of stack space at the cost of
somewhat larger and slower code.
Project>Options>C/C++ Compiler>Code>Reduce stack usage
--regvar_r4
Syntax --regvar_r4
Description Use this option to reserve the register R4 for use by global register variables, declared
with the __regvar attribute. This can give more efficient code if used on frequently
used variables.
AFE1_AFE2-1:1
Compiler options
--regvar_r5
Syntax --regvar_r5
Description Use this option to reserve the register R5 for use by global register variables, declared
with the __regvar attribute. This can give more efficient code if used on frequently
used variables.
--relaxed_fp
Syntax --relaxed_fp
Description Use this option to allow the compiler to relax the language rules and perform more
aggressive optimization of floating-point expressions. This option improves
performance for floating-point expressions that fulfill these conditions:
● The expression consists of both single and double-precision values
● The double-precision values can be converted to single precision without loss of
accuracy
● The result of the expression is converted to single precision.
Note: Performing the calculation in single precision instead of double precision might
cause a loss of accuracy.
The C standard states that 3.0 in this example has the type double and therefore the
whole expression should be evaluated in double precision. However, when the
--relaxed_fp option is used, 3.0 will be converted to float and the whole expression
can be evaluated in float precision.
To set related options, choose:
Project>Options>C/C++ Compiler>Language 2>Floating-point semantics
295
AFE1_AFE2-1:1
Descriptions of compiler options
--remarks
Syntax --remarks
Description The least severe diagnostic messages are called remarks. A remark indicates a source
code construct that may cause strange behavior in the generated code. By default, the
compiler does not generate remarks. Use this option to make the compiler generate
remarks.
--require_prototypes
Syntax --require_prototypes
Description Use this option to force the compiler to verify that all functions have proper prototypes.
Using this option means that code containing any of the following will generate an error:
● A function call of a function with no declaration, or with a Kernighan & Ritchie
C declaration
● A function definition of a public function with no previous prototype declaration
● An indirect function call through a function pointer with a type that does not include
a prototype.
Project>Options>C/C++ Compiler>Language 1>Require prototypes
--ropi
Syntax --ropi
Description Use this option to make the compiler generate position-independent code and read-only
data.
The --ropi option has some drawbacks and limitations, see Drawbacks and
limitations, page 80.
Note: The --ropi option is deprecated in IAR Embedded Workbench for MSP430
from version 6.50.
AFE1_AFE2-1:1
Compiler options
See also Position-independent code and read-only data, page 80, __no_pic, page 326, and
--no_rw_dynamic_init, page 287. For information about the preprocessor symbol
__ROPI__, see Description of predefined preprocessor symbols, page 370.
--save_reg20
Syntax --save_reg20
Description Use this option to make all interrupt functions be treated as a __save_reg20 declared
function. This means that you do not have to explicitly use the __save_reg20 keyword
on any interrupt functions.
This is necessary if your application requires that all 20 bits of registers are preserved.
The drawback is that the code will be somewhat slower.
Note: This option is only available when compiling for the MSP430X architecture.
--segment
Syntax --segment __memory_attribute=BASENAME
--segment specialsegment=NAME
Parameters
__memory_attribute Can be one of:
297
AFE1_AFE2-1:1
Descriptions of compiler options
Description The compiler places functions and data objects into named segments which are referred
to by the IAR XLINK Linker. Use the --segment option to perform one of these
operations:
● To place data objects declared with the __memory_attribute in segments with
names that begin with BASENAME.
● To change the name of a special segment to NAME.
This is useful if you want to place your code or data in different address ranges and you
find the @ notation, alternatively the #pragma location directive, insufficient. Note
that any changes to the segment names require corresponding modifications in the linker
configuration file.
This command places the __data16 int a; defined variable in the MYDATA_Z
segment:
This command names the segment that contains interrupt vectors to MYINTS instead of
the default name INTVEC:
--segment intvec=MYINTS
See also Controlling data and function placement in memory, page 236 and Summary of extended
keywords, page 320.
Project>Options>C/C++ Compiler>Output>Override segment base name
AFE1_AFE2-1:1
Compiler options
--silent
Syntax --silent
Description By default, the compiler issues introductory messages and a final statistics report. Use
this option to make the compiler operate without sending these messages to the standard
output stream (normally the screen).
This option does not affect the display of error and warning messages.
This option is not available in the IDE.
--strict
Syntax --strict
Description By default, the compiler accepts a relaxed superset of Standard C and C++. Use this
option to ensure that the source code of your application instead conforms to strict
Standard C and C++.
Note: The -e option and the --strict option cannot be used at the same time.
--system_include_dir
Syntax --system_include_dir path
Parameters
path The path to the system include files, see Rules for specifying
a filename or directory as parameters, page 264.
Description By default, the compiler automatically locates the system include files. Use this option
to explicitly specify a different path to the system include files. This might be useful if
you have not installed IAR Embedded Workbench in the default location.
See also --dlib, page 276, --dlib_config, page 277, and --no_system_include, page 288.
This option is not available in the IDE.
299
AFE1_AFE2-1:1
Descriptions of compiler options
--use_c++_inline
Syntax --use_c++_inline
Description Standard C uses slightly different semantics for the inline keyword than C++ does.
Use this option if you want C++ semantics when you are using C.
--version
Syntax --version
Description Use this option to make the compiler send version information to the console and then
exit.
This option is not available in the IDE.
--vla
Syntax --vla
Description Use this option to enable support for C99 variable length arrays. Such arrays are located
on the heap. This option requires Standard C and cannot be used together with the
--c89 compiler option.
Note: --vla should not be used together with the longjmp library function, as that can
lead to memory leakages.
AFE1_AFE2-1:1
Compiler options
--warn_about_c_style_casts
Syntax --warn_about_c_style_casts
Description Use this option to make the compiler warn when C-style casts are used in C++ source
code.
This option is not available in the IDE.
--warnings_affect_exit_code
Syntax --warnings_affect_exit_code
Description By default, the exit code is not affected by warnings, because only errors produce a
non-zero exit code. With this option, warnings will also generate a non-zero exit code.
This option is not available in the IDE.
--warnings_are_errors
Syntax --warnings_are_errors
Description Use this option to make the compiler treat all warnings as errors. If the compiler
encounters an error, no object code is generated. Warnings that have been changed into
remarks are not treated as errors.
Note: Any diagnostic messages that have been reclassified as warnings by the option
--diag_warning or the #pragma diag_warning directive will also be treated as
errors when --warnings_are_errors is used.
301
AFE1_AFE2-1:1
Descriptions of compiler options
AFE1_AFE2-1:1
Data representation
● Alignment
● Pointer types
● Structure types
● Type qualifiers
See the chapter Efficient coding for embedded applications for information about
which data types provide the most efficient code for your application.
Alignment
Every C data object has an alignment that controls how the object can be stored in
memory. Should an object have an alignment of, for example, 4, it must be stored on an
address that is divisible by 4.
The reason for the concept of alignment is that some processors have hardware
limitations for how the memory can be accessed.
Assume that a processor can read 4 bytes of memory using one instruction, but only
when the memory read is placed on an address divisible by 4. Then, 4-byte objects, such
as long integers, will have alignment 4.
Another processor might only be able to read 2 bytes at a time; in that environment, the
alignment for a 4-byte long integer might be 2.
A structure type will have the same alignment as the structure member with the most
strict alignment. To decrease the alignment requirements on the structure and its
members, use #pragma pack.
All data types must have a size that is a multiple of their alignment. Otherwise, only the
first element of an array would be guaranteed to be placed in accordance with the
alignment requirements. This means that the compiler might add pad bytes at the end of
303
AFE1_AFE2-1:1
Basic data types—integer types
the structure. For more information about pad bytes, see Packed structure types, page
311.
Note that with the #pragma data_alignment directive you can increase the
alignment demands on specific variables.
AFE1_AFE2-1:1
Data representation
BOOL
The bool data type is supported by default in the C++ language. If you have enabled
language extensions, the bool type can also be used in C source code if you include the
file stdbool.h. This will also enable the boolean values false and true.
When IAR Systems language extensions are enabled, and in C++, the enum constants
and types can also be of the type long, unsigned long, long long, or unsigned
long long.
To make the compiler use a larger type than it would automatically use, define an enum
constant with a large enough value. For example:
/* Disables usage of the char type for enum */
enum Cards{Spade1, Spade2,
DontUseChar=257};
305
AFE1_AFE2-1:1
Basic data types—integer types
BITFIELDS
In Standard C, int, signed int, and unsigned int can be used as the base type for
integer bitfields. In standard C++, and in C when language extensions are enabled in the
compiler, any integer or enumeration type can be used as the base type. It is
implementation defined whether a plain integer type (char, short, int, etc) results in
a signed or unsigned bitfield.
Bitfields in expressions will have the same data type as the integer base type.
In the IAR C/C++ Compiler for MSP430, plain integer types are treated as signed.
Bitfields in expressions are treated as int if int can represent all values of the bitfield.
Otherwise, they are treated as the bitfield base type.
Each bitfield is placed into a container of its base type from the least significant bit to
the most significant bit. If the last container is of the same type and has enough bits
available, the bitfield is placed into this container, otherwise a new container is
allocated. This allocation scheme is referred to as the disjoint type bitfield allocation.
If you use the directive #pragma bitfields=reversed, bitfields are placed from the
most significant bit to the least significant bit in each container. See bitfields, page 334.
Assume this example:
struct BitfieldExample
{
uint32_t a : 12;
uint16_t b : 3;
uint16_t c : 7;
uint8_t d;
};
To place the second bitfield, b, a new container is allocated at offset 4, because the type
of the bitfield is not the same as that of the previous one. b is placed into the least
significant three bits of this container.
The third bitfield, c, has the same type as b and fits into the same container.
The fourth member, d, is allocated into the byte at offset 6. d cannot be placed into the
same container as b and c because it is not a bitfield, it is not of the same type, and it
would not fit.
When using reverse order, each bitfield is instead placed starting from the most
significant bit of its container.
AFE1_AFE2-1:1
Data representation
The compiler does not support subnormal numbers. All operations that should produce
subnormal numbers will instead generate zero.
FLOATING-POINT ENVIRONMENT
Exception flags are not supported. The feraiseexcept function does not raise any
exceptions.
307
AFE1_AFE2-1:1
Basic data types—floating-point types
The precision of the float operators (+, -, *, and /) is approximately 7 decimal digits.
The precision of the float operators (+, -, *, and /) is approximately 15 decimal digits.
AFE1_AFE2-1:1
Data representation
Note: This differs slightly from the standard IEEE754 representation and allows the
runtime library to be smaller and faster.
Note: The IAR CLIB Library does not fully support the special cases of floating-point
numbers, such as infinity, NaN. A library function which gets one of these special cases
of floating-point numbers as an argument might behave unexpectedly.
Pointer types
The compiler has two basic types of pointers: function pointers and data pointers.
FUNCTION POINTERS
For the MSP430 architecture and for the MSP430X architecture when using the Small
code model, function pointers are always 16 bits. For the MSP430X architecture when
using the Large code model, function pointers are 20 bits and they can address the entire
1 Mbyte of memory. See this table:
Architecture Data model Code model In register In memory
MSP430 — — One 16-bit register 2 bytes
MSP430X Any Small One 16-bit register 2 bytes
MSP430X Small Large Two 16-bit registers 4 bytes
MSP430X Medium/Large Large One 20-bit register 4 bytes
Table 35: Function pointers
Note: If ROPI is enabled, a normal function pointer holds the linked address of a
function. The actual address is only computed when the function is called. You can use
the function type attribute __no_pic to change this behavior, see __no_pic, page 326.
DATA POINTERS
These data pointers are available:
Keyword Pointer size Index type Address range In register In memory
__data16 16 bits signed int 0x0–0xFFFF One 16-bit register 2 bytes
__data20* 20 bits signed long 0x0–0xFFFFF One 20-bit register 4 bytes
Table 36: Data pointers
* The __data20 pointer type is not available for the MSP430X architecture when using
the Small data model nor for the MSP430 architecture.
Note: A data pointer always holds the actual address of an object, regardless of whether
ROPI is enabled or not.
309
AFE1_AFE2-1:1
Pointer types
CASTING
Casts between pointers have these characteristics:
● Casting a value of an integer type to a pointer of a smaller type is performed by
truncation
● Casting a value of an integer type to a pointer of a larger type is performed by zero
extension
● Casting a pointer type to a smaller integer type is performed by truncation
● Casting a pointer type to a larger integer type is performed by zero extension
● Casting a data pointer to a function pointer and vice versa is illegal
● Casting a function pointer to an integer type gives an undefined result
● Casting from a smaller pointer to a larger pointer is performed by zero extension
● Casting from a larger pointer to a smaller pointer is performed by truncation.
size_t
size_t is the unsigned integer type of the result of the sizeof operator. For the
MSP430 architecture, and for the MSP430X architecture in the Small and Medium data
models, the type used for size_t is unsigned int. In the Large data model, the type
used for size_t is unsigned long int.
ptrdiff_t
ptrdiff_t is the signed integer type of the result of subtracting two pointers. For the
MSP430 architecture, and for the MSP430X architecture in the Small and Medium data
models, the type used for ptrdiff_t is signed int. In the Large data model, the type
used for inptr_t is signed long int.
Note: It is sometimes possible to create an object that is so large that the result of
subtracting two pointers in that object is negative. See this example:
char buff[60000]; /* Assuming ptrdiff_t is a 16-bit */
char *p1 = buff; /* signed integer type. */
char *p2 = buff + 60000;
ptrdiff_t diff = p2 - p1;
intptr_t
intptr_t is a signed integer type large enough to contain a void *. For the MSP430
architecture, and for the MSP430X architecture in the Small and Medium data models,
the type used for inptr_t is signed int. In the Large data model, the type used for
inptr_t is signed long int.
AFE1_AFE2-1:1
Data representation
uintptr_t
uintptr_t is equivalent to intptr_t, with the exception that it is unsigned.
Structure types
The members of a struct are stored sequentially in the order in which they are
declared: the first member has the lowest memory address.
GENERAL LAYOUT
Members of a struct are always allocated in the order specified in the declaration.
Each member is placed in the struct according to the specified alignment (offsets).
struct First
{
char c;
short s;
} s;
The alignment of the structure is 2 bytes, and a pad byte must be inserted to give
short s the correct alignment.
311
AFE1_AFE2-1:1
Structure types
Special care is also needed when creating and using pointers to misaligned members.
For direct access to misaligned members in a packed struct, the compiler will emit the
correct (but slower and larger) code when needed. However, when a misaligned member
is accessed through a pointer to the member, the normal (smaller and faster) code is
used. In the general case, this will not work, because the normal code might depend on
the alignment being correct.
This example declares a packed structure:
#pragma pack(1)
struct S
{
char c;
short s;
};
#pragma pack()
The next example declares a new non-packed structure, S2, that contains the structure s
declared in the previous example:
struct S2
{
struct S s;
long l;
};
The structure S will use the memory layout, size, and alignment described in the
previous example. The alignment of the member l is 2, which means that alignment of
the structure S2 will become 2.
For more information, see Alignment of elements in a structure, page 234.
AFE1_AFE2-1:1
Data representation
Type qualifiers
According to the C standard, volatile and const are type qualifiers.
● The compiler considers each read and write access to an object declared volatile
as an access
● The unit for the access is either the entire object or, for accesses to an element in a
composite object—such as an array, struct, class, or union—the element. For
example:
char volatile a;
a = 5; /* A write access */
a += 6; /* First a read then a write access */
● An access to a bitfield is treated as an access to the underlying type
● Adding a const qualifier to a volatile object will make write accesses to the
object impossible. However, the object will be placed in RAM as specified by the C
standard.
However, these rules are not detailed enough to handle the hardware-related
requirements. The rules specific to the IAR C/C++ Compiler for MSP430 are described
below.
313
AFE1_AFE2-1:1
Type qualifiers
The segment FLASH contains the initializers. They must be flashed manually when the
application starts up.
Thereafter, the initializers can be reflashed with other values at any time.
AFE1_AFE2-1:1
Data representation
315
AFE1_AFE2-1:1
Data types in C++
AFE1_AFE2-1:1
Extended keywords
● General syntax rules for extended keywords
Use the -e compiler option to enable language extensions. See -e, page 278.
TYPE ATTRIBUTES
Type attributes define how a function is called, or how a data object is accessed. This
means that if you use a type attribute, it must be specified both when a function or data
object is defined and when it is declared.
You can either place the type attributes explicitly in your declarations, or use the pragma
directive #pragma type_attribute.
Type attributes can be further divided into memory type attributes and general type
attributes. Memory type attributes are referred to as simply memory attributes in the rest
of the documentation.
317
AFE1_AFE2-1:1
General syntax rules for extended keywords
Memory attributes
A memory attribute corresponds to a certain logical or physical memory in the
microcontroller.
Available data memory attributes:
__regvar.
Data objects, functions, and destinations of pointers or C++ references always have a
memory attribute. If no attribute is explicitly specified in the declaration or by the
pragma directive #pragma type_attribute, an appropriate default attribute is
implicitly used by the compiler. You can specify one memory attribute for each level of
pointer indirection.
You can specify as many type attributes as required for each level of pointer indirection.
AFE1_AFE2-1:1
Extended keywords
In all cases, if a memory attribute is not specified, an appropriate default memory type
is used, which depends on the data model in use.
Using a type definition can sometimes make the code clearer:
typedef __data16 int d16_int;
d16_int *q1;
d16_int is a typedef for integers in data16 memory. The variable q1 can point to such
integers.
You can also use the #pragma type_attributes directive to specify type attributes
for a declaration. The type attributes specified in the pragma directive are applied to the
data object or typedef being declared.
#pragma type_attribute=__data16
int * q2;
or
void (__interrupt my_handler)(void);
OBJECT ATTRIBUTES
Normally, object attributes affect the internal functionality of functions and data objects,
but not directly how the function is called or how the data is accessed. This means that
an object attribute does not normally need to be present in the declaration of an object.
Any exceptions to this rule are noted in the description of the attribute.
These object attributes are available:
● Object attributes that can be used for variables:
__no_alloc, __no_alloc16, __no_alloc_str, __no_alloc_str16,
__no_init, __persistent, __ro_placement
319
AFE1_AFE2-1:1
Summary of extended keywords
You can specify as many object attributes as required for a specific function or data
object.
For more information about location and @, see Controlling data and function
placement in memory, page 236. For more information about vector, see vector, page
354.
Note: Object attributes cannot be used in combination with the typedef keyword.
AFE1_AFE2-1:1
Extended keywords
__cc_rom
Syntax See Syntax for type attributes used on functions, page 319.
Description The __cc_rom keyword makes a function use the ROM calling convention instead of
the default calling convention.
321
AFE1_AFE2-1:1
Descriptions of extended keywords
__cc_version1
Syntax See Syntax for type attributes used on functions, page 319.
Description The __cc_version1 keyword is available for backward compatibility of the interface
for calling assembler routines from C. It makes a function use the calling convention of
the IAR C/C++ Compiler for MSP430 version 1.x–3.x instead of the default calling
convention.
__cc_version2
Syntax See Syntax for type attributes used on functions, page 319.
Description The __cc_version2 keyword sets the default calling convention of the interface for
calling assembler routines from C. It makes a function use the calling convention of the
IAR C/C++ Compiler for MSP430 version 4.x and later.
__data16
Syntax See Syntax for type attributes used on data objects, page 318.
Description The __data16 memory attribute overrides the default storage of variables and places
individual variables and constants in data16 memory, which is the entire 64 Kbytes of
memory in the MSP430 architecture and the lower 64 Kbytes in the MSP430X
architecture. You can also use the __data16 attribute to create a pointer explicitly
pointing to an object located in the data16 memory.
AFE1_AFE2-1:1
Extended keywords
__data20
Syntax See Syntax for type attributes used on data objects, page 318.
Description The __data20 memory attribute overrides the default storage of variables and places
individual variables and constants in data20 memory, which is the entire 1 Mbyte of
memory in the MSP430X architecture. You can also use the __data20 attribute to
create a pointer explicitly pointing to an object located in the data20 memory.
The __data20 attribute cannot be used in the Small data model.
__interrupt
Syntax See Syntax for type attributes used on functions, page 319.
Description The __interrupt keyword specifies interrupt functions. To specify one or several
interrupt vectors, use the #pragma vector directive. The range of the interrupt vectors
depends on the device used. It is possible to define an interrupt function without a vector,
but then the compiler will not generate an entry in the interrupt vector table.
An interrupt function must have a void return type and cannot have any parameters.
The header file iodevice.h, where device corresponds to the selected device,
contains predefined names for the existing interrupt vectors.
To make sure that the interrupt handler executes as fast as possible, you should compile
it with -Ohs, or use #pragma optimize=speed if the module is compiled with another
optimization goal.
See also Interrupt functions, page 73, vector, page 354, and INTVEC, page 399.
323
AFE1_AFE2-1:1
Descriptions of extended keywords
__intrinsic
Description The __intrinsic keyword is reserved for compiler internal use only.
__monitor
Syntax See Syntax for type attributes used on functions, page 319.
Description The __monitor keyword causes interrupts to be disabled during execution of the
function. This allows atomic operations to be performed, such as operations on
semaphores that control access to resources by multiple processes. A function declared
with the __monitor keyword is equivalent to any other function in all other respects.
See also Monitor functions, page 76. For information about related intrinsic functions, see
__disable_interrupt, page 361, __enable_interrupt, page 362, __get_interrupt_state,
page 362, and __set_interrupt_state, page 366, respectively.
__no_alloc, __no_alloc16
Syntax See Syntax for object attributes, page 320.
Description Use the __no_alloc or __no_alloc16 object attribute on a constant to make the
constant available in the executable file without occupying any space in the linked
application.
You cannot access the contents of such a constant from your application. You can take
its address, which is an integer offset to the segment of the constant. The type of the
offset is unsigned long when __no_alloc is used, and unsigned short when
__no_alloc16 is used.
AFE1_AFE2-1:1
Extended keywords
__no_alloc_str, __no_alloc_str16
Syntax __no_alloc_str(string_literal @ segment)
and
__no_alloc_str16(string_literal @ segment)
where
string_literal The string literal that you want to make available in the
executable file.
segment The name of the segment to place the string literal in.
void
foo(int i, double d)
{
DBGPRINTF("The value of i is: %d, the value of d is: %f",i,d);
}
Depending on your debugger and the runtime support, this could produce trace output
on the host computer.
Note: There is no such runtime support in C-SPY, unless you use an external plugin
module.
325
AFE1_AFE2-1:1
Descriptions of extended keywords
__no_init
Syntax See Syntax for object attributes, page 320.
Description Use the __no_init keyword to place a data object in non-volatile memory. This means
that the initialization of the variable, for example at system startup, is suppressed.
__no_multiplier
Syntax See Syntax for type attributes used on functions, page 319.
Description The __no_multiplier keyword suppresses generation of code that directly accesses
the hardware multiplier. When using this keyword, the result is the same as when
compiling without the --multiplier command line option.
Note: The linker might still redirect function calls, including calls to internal runtime
library routines, to variants that use the hardware multiplier.
__no_pic
Syntax See Syntax for type attributes used on functions, page 319.
Description The __no_pic memory attribute allows position-independent code to call functions
that are not position-independent. The attribute can only be used on function pointers
and only when the --ropi option is used. Such function pointers are called with the
normal calling sequence instead of with the position-independent one.
See also Assembler instructions used for calling functions, page 189 and Position-independent
code and read-only data, page 80.
AFE1_AFE2-1:1
Extended keywords
__noreturn
Syntax See Syntax for object attributes, page 320.
Description The __noreturn keyword can be used on a function to inform the compiler that the
function will not return. If you use this keyword on such functions, the compiler can
optimize more efficiently. Examples of functions that do not return are abort and exit.
Note: At optimization levels medium or high, the __noreturn keyword might cause
incorrect call stack debug information at any point where it can be determined that the
current function cannot return.
__persistent
Syntax See Syntax for object attributes, page 320.
Description Global or static variables defined with the __persistent attribute will not be
initialized by cstartup, but only by a code downloader or similar add-on functionality.
This attribute cannot be used together with any of the keywords const or __no_init,
and __persistent data cannot be located to an absolute address (using the @
operator).
__ramfunc
Syntax See Syntax for object attributes, page 320.
Description The __ramfunc keyword makes a function execute in RAM. Two code segments will
be created: one for the RAM execution, and one for the ROM initialization.
Functions declared __ramfunc are by default stored in the CODE_I segment.
This attribute cannot be used if you have specified the --ropi option.
327
AFE1_AFE2-1:1
Descriptions of extended keywords
__raw
Syntax See Syntax for object attributes, page 320.
__regvar
Syntax See Syntax for type attributes used on functions, page 319.
Description This keyword is used for declaring that a global or static variable should be placed
permanently in the specified register. The registers R4–R5 can be used for this purpose,
provided that they have been reserved with one of the --regvar_r4 or --regvar_r5
compiler options.
The __regvar attribute can be used on integer types, pointers, 32-bit floating-point
numbers, structures with one element and unions of all these. However, it is not possible
to point to an object that has been declared __regvar. An object declared __regvar
cannot have an initial value.
Note: If a module in your application has been compiled using --regvar_r4, it can
only be linked with modules that have been compiled with either --regvar_r4 or
--lock_r4. The same is true for --regvar_r5/--lock_r5.
__root
Syntax See Syntax for object attributes, page 320.
AFE1_AFE2-1:1
Extended keywords
Description A function or variable with the __root attribute is kept whether or not it is referenced
from the rest of the application, provided its module is included. Program modules are
always included and library modules are only included if needed.
See also For more information about modules, segments, and the link process, see the IAR Linker
and Library Tools Reference Guide.
__ro_placement
Syntax See Syntax for object attributes, page 320.
Unlike most object attributes, when --ropi is enabled the __ro_placement attribute
must be specified both when a data object is defined and when it is declared.
Description The __ro_placement attribute specifies that a data object should be placed in
read-only memory. There are two cases where you might want to use this object
attribute:
● Data objects declared const volatile are by default placed in read-write
memory. Use the __ro_placement object attribute to place the data object in
read-only memory instead.
● In C++, a data object declared const and that needs dynamic initialization is placed
in read-write memory and initialized at system startup. If you use the
__ro_placement object attribute, the compiler will give an error message if the
data object needs dynamic initialization.
You can only use the __ro_placement object attribute on const objects.
You can use the __ro_placement attribute with C++ objects if the compiler can
optimize the C++ dynamic initialization of the data objects into static initialization. This
is possible only for relatively simple constructors that have been defined in the header
files of the relevant class definitions, so that they are visible to the compiler. If the
compiler cannot find the constructor, or if the constructor is too complex, an error
message will be issued (Error[Go023]) and the compilation will fail.
__save_reg20
Syntax See Syntax for object attributes, page 320.
329
AFE1_AFE2-1:1
Descriptions of extended keywords
Description When compiling for the MSP430X architecture in the Small data model, use this
keyword to save and restore all 20 bits of the registers that are used, instead of only 16
bits, which are saved and restored by normal functions. This keyword will make the
function save all registers and not only the ones used by the function to guarantee that
20-bit registers are not destroyed by subsequent calls.
This may be necessary if the function is called from assembler routines that use the
upper 4 bits of the 20-bit registers.
Note: The __save_reg20 keyword has only effect when compiling for the MSP430X
architecture.
See also Interrupt functions for the MSP430X architecture, page 75.
__task
Syntax See Syntax for type attributes used on functions, page 319.
Description This keyword allows functions to relax the rules for preserving registers. Typically, the
keyword is used on the start function for a task in an RTOS.
By default, functions save the contents of used preserved registers on the stack upon
entry, and restore them at exit. Functions that are declared __task do not save all
registers, and therefore require less stack space.
Because a function declared __task can corrupt registers that are needed by the calling
function, you should only use __task on functions that do not return or call such a
function from assembler code.
The function main can be declared __task, unless it is explicitly called from the
application. In real-time applications with more than one task, the root function of each
task can be declared __task.
AFE1_AFE2-1:1
Pragma directives
● Summary of pragma directives
331
AFE1_AFE2-1:1
Summary of pragma directives
AFE1_AFE2-1:1
Pragma directives
Note: For portability reasons, see also Recognized pragma directives (6.10.6), page
421.
basic_template_matching
Syntax #pragma basic_template_matching
Description Use this pragma directive in front of a template function declaration to make the
function fully memory-attribute aware, in the rare cases where this is useful. That
template function will then match the template without the modifications, see Templates
and data memory attributes, page 214.
void MyF()
{
fun((int __data16 *) 0); // T = int __data16
}
333
AFE1_AFE2-1:1
Descriptions of pragma directives
bis_nmi_ie1
Syntax #pragma bis_nmi_ie1=mask
Parameters
mask A constant expression
Description Use this pragma directive for changing the interrupt control bits in the register IE, within
an NMI service routine. A BIS.W #mask, IE1 instruction is generated immediately
before the RETI instruction at the end of the function, after any POP instructions.
The effect is that NMI interrupts cannot occur until after the BIS instruction. The
advantage of placing it at the end of the POP instructions is that less stack will be used
in the case of nested interrupts.
Example In the following example, the OFIE bit will be set as the last instruction before the RETI
instruction:
#pragma bis_nmi_ie1=OFIE
#pragma vector=NMI_VECTOR
__interrupt void myInterruptFunction(void)
{
...
}
bitfields
Syntax #pragma bitfields={reversed|default}
Parameters
reversed Bitfield members are placed from the most significant bit to
the least significant bit.
default Bitfield members are placed from the least significant bit to
the most significant bit.
Description Use this pragma directive to control the order of bitfield members.
AFE1_AFE2-1:1
Pragma directives
calls
Syntax #pragma calls=function[, function...]
Parameters
function Any declared function
Description Use this pragma directive to list the functions that can be indirectly called in the
following statement. This information can be used for stack usage analysis in the linker.
Note: For an accurate result, you must list all possible called functions.
call_graph_root
Syntax #pragma call_graph_root[=category]
Parameters
category A string that identifies an optional call graph root category
Description Use this pragma directive to specify that, for stack usage analysis purposes, the
immediately following function is a call graph root. You can also specify an optional
335
AFE1_AFE2-1:1
Descriptions of pragma directives
category. The compiler will usually automatically assign a call graph root category to
interrupt and task functions. If you use the #pragma call_graph_root directive on
such a function you will override the default category. You can specify any string as a
category.
constseg
Syntax #pragma constseg=[__memoryattribute ]{SEGMENT_NAME|default}
Parameters
__memoryattribute An optional memory attribute denoting in what memory the
segment will be placed; if not specified, default memory is
used.
SEGMENT_NAME A user-defined segment name; cannot be a segment name
predefined for use by the compiler and linker.
default Uses the default segment for constants.
Description This legacy pragma directive is supported for backward compatibility reasons. It can be
used for placing constant variables in a named segment. The segment name cannot be a
segment name predefined for use by the compiler and linker. The setting remains active
until you turn it off again with the #pragma constseg=default directive.
data_alignment
Syntax #pragma data_alignment=expression
Parameters
expression A constant which must be a power of two (1, 2, 4, etc.).
Description Use this pragma directive to give the immediately following variable a higher (more
strict) alignment of the start address than it would otherwise have. This directive can be
used on variables with static and automatic storage duration.
AFE1_AFE2-1:1
Pragma directives
When you use this directive on variables with automatic storage duration, there is an
upper limit on the allowed alignment for each function, determined by the calling
convention used.
Note: Normally, the size of a variable is a multiple of its alignment. The
data_alignment directive only affects the alignment of the variable’s start address,
and not its size, and can therefore be used for creating situations where the size is not a
multiple of the alignment.
Note: To comply with the ISO C11 standard and later, it is recommended to use the
alignment specifier _Alignas for C code. To comply with the C++11 standard and later,
it is recommended to use the alignment specifier alignas for C++ code.
dataseg
Syntax #pragma dataseg=[__memoryattribute]{SEGMENT_NAME|default}
Parameters
__memoryattribute An optional memory attribute denoting in what memory the
segment will be placed; if not specified, default memory is
used.
SEGMENT_NAME A user-defined segment name; cannot be a segment name
predefined for use by the compiler and linker.
default Uses the default segment.
Description This legacy pragma directive is supported for backward compatibility reasons. It can be
used for placing variables in a named segment. The segment name cannot be a segment
name predefined for use by the compiler and linker. The variable will not be initialized
at startup, and can for this reason not have an initializer, which means it must be declared
__no_init. The setting remains active until you turn it off again with the #pragma
dataseg=default directive.
default_function_attributes
Syntax #pragma default_function_attributes=[ attribute...]
337
AFE1_AFE2-1:1
Descriptions of pragma directives
object_attribute
@ segment_name
Parameters
type_attribute See Type attributes, page 317.
object_attribute See Object attributes, page 319.
@ segment_name See Data and function placement in segments, page 239.
Description Use this pragma directive to set default segment placement, type attributes, and object
attributes for function declarations and definitions. The default settings are only used for
declarations and definitions that do not specify type or object attributes or location in
some other way.
Specifying a default_function_attributes pragma directive with no attributes,
restores the initial state where no such defaults have been applied to function
declarations and definitions.
default_variable_attributes
Syntax #pragma default_variable_attributes=[ attribute...]
AFE1_AFE2-1:1
Pragma directives
Parameters
type_attribute See Type attributes, page 317.
object_attributes See Object attributes, page 319.
@ segment_name See Data and function placement in segments, page 239.
Description Use this pragma directive to set default segment placement, type attributes, and object
attributes for declarations and definitions of variables with static storage duration. The
default settings are only used for declarations and definitions that do not specify type or
object attributes or location in some other way.
Specifying a default_variable_attributes pragma directive with no attributes
restores the initial state of no such defaults being applied to variables with static storage
duration.
diag_default
Syntax #pragma diag_default=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe177.
Description Use this pragma directive to change the severity level back to the default, or to the
severity level defined on the command line by any of the options --diag_error,
--diag_remark, --diag_suppress, or --diag_warnings, for the diagnostic
339
AFE1_AFE2-1:1
Descriptions of pragma directives
messages specified with the tags. This level remains in effect until changed by another
diagnostic-level pragma directive.
diag_error
Syntax #pragma diag_error=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe177.
Description Use this pragma directive to change the severity level to error for the specified
diagnostics. This level remains in effect until changed by another diagnostic-level
pragma directive.
diag_remark
Syntax #pragma diag_remark=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe177.
Description Use this pragma directive to change the severity level to remark for the specified
diagnostic messages. This level remains in effect until changed by another
diagnostic-level pragma directive.
diag_suppress
Syntax #pragma diag_suppress=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe117.
AFE1_AFE2-1:1
Pragma directives
Description Use this pragma directive to suppress the specified diagnostic messages. This level
remains in effect until changed by another diagnostic-level pragma directive.
diag_warning
Syntax #pragma diag_warning=tag[,tag,...]
Parameters
tag The number of a diagnostic message, for example, the
message number Pe826.
Description Use this pragma directive to change the severity level to warning for the specified
diagnostic messages. This level remains in effect until changed by another
diagnostic-level pragma directive.
error
Syntax #pragma error message
Parameters
message A string that represents the error message.
Description Use this pragma directive to cause an error message when it is parsed. This mechanism
is different from the preprocessor directive #error, because the #pragma error
directive can be included in a preprocessor macro using the _Pragma form of the
directive and only causes an error if the macro is used.
If FOO_AVAILABLE is zero, an error will be signaled if the FOO macro is used in actual
source code.
341
AFE1_AFE2-1:1
Descriptions of pragma directives
include_alias
Syntax #pragma include_alias ("orig_header" , "subst_header")
#pragma include_alias (<orig_header> , <subst_header>)
Parameters
orig_header The name of a header file for which you want to create an
alias.
subst_header The alias for the original header file.
Description Use this pragma directive to provide an alias for a header file. This is useful for
substituting one header file with another, and for specifying an absolute path to a relative
file.
This pragma directive must appear before the corresponding #include directives and
subst_header must match its corresponding #include directive exactly.
This example will substitute the relative file stdio.h with a counterpart located
according to the specified path.
inline
Syntax #pragma inline[=forced|=never]
Parameters
No parameter Has the same effect as the inline keyword.
forced Disables the compiler’s heuristics and forces inlining.
never Disables the compiler’s heuristics and makes sure that the
function will not be inlined.
Description Use #pragma inline to advise the compiler that the function defined immediately after
the directive should be inlined according to C++ inline semantics.
Specifying #pragma inline=forced will always inline the defined function. If the
compiler fails to inline the function for some reason, for example due to recursion, a
warning message is emitted.
AFE1_AFE2-1:1
Pragma directives
language
Syntax #pragma language={extended|default|save|restore}
Parameters
extended Enables the IAR Systems language extensions from the first
use of the pragma directive and onward.
default From the first use of the pragma directive and onward,
restores the settings for the IAR Systems language
extensions to whatever that was specified by compiler
options.
save|restore Saves and restores, respectively, the IAR Systems language
extensions setting around a piece of source code.
Each use of save must be followed by a matching restore
in the same file without any intervening #include directive.
Description Use this pragma directive to control the use of language extensions.
Example At the top of a file that needs to be compiled with IAR Systems extensions enabled:
#pragma language=extended
/* The rest of the file. */
Around a particular part of the source code that needs to be compiled with IAR Systems
extensions enabled, but where the state before the sequence cannot be assumed to be the
same as that specified by the compiler options in use:
#pragma language=save
#pragma language=extended
/* Part of source code. */
#pragma language=restore
343
AFE1_AFE2-1:1
Descriptions of pragma directives
location
Syntax #pragma location={address|NAME}
Parameters
address The absolute address of the global or static variable for which
you want an absolute location.
NAME A user-defined segment name—cannot be a segment name
predefined for use by the compiler and linker.
Description Use this pragma directive to specify the location—the absolute address—of the global
or static variable whose declaration follows the pragma directive. The variable must be
declared either __no_init or const. Alternatively, the directive can take a string
specifying a segment for placing either a variable or a function whose declaration
follows the pragma directive. Do not place variables that would normally be in different
segments—for example, variables declared as __no_init and variables declared as
const—in the same named segment.
#pragma segment="MY_SEG"
#pragma location="MY_SEG"
__no_init char PORT2; /* PORT2 is located in segment MY_SEG */
See also Controlling data and function placement in memory, page 236 and Placing user-defined
segments, page 105.
message
Syntax #pragma message(message)
Parameters
message The message that you want to direct to the standard output
stream.
AFE1_AFE2-1:1
Pragma directives
Description Use this pragma directive to make the compiler print a message to the standard output
stream when the file is compiled.
no_epilogue
Syntax #pragma no_epilogue
Description Use this pragma directive to use a local return sequence instead of a call to the library
routine ?EpilogueN. This pragma directive can be used when a function needs to exist
on its own as in for example a bootloader that needs to be independent of the libraries it
is replacing.
object_attribute
Syntax #pragma object_attribute=object_attribute[ object_attribute...]
Parameters For information about object attributes that can be used with this pragma directive, see
Object attributes, page 319.
Description Use this pragma directive to add one or more IAR-specific object attributes to the
declaration or definition of a variable or function. Object attributes affect the actual
variable or function and not its type. When you define a variable or function, the union
of the object attributes from all declarations including the definition, is used.
is equivalent to:
__no_init char bar;
See also General syntax rules for extended keywords, page 317.
345
AFE1_AFE2-1:1
Descriptions of pragma directives
optimize
Syntax #pragma optimize=[goal][level][disable]
Parameters
goal Choose between:
size, optimizes for size
Description Use this pragma directive to decrease the optimization level, or to turn off some specific
optimizations. This pragma directive only affects the function that follows immediately
after the directive.
The parameters size, balanced, speed, and no_size_constraints only have
effect on the high optimization level and only one of them can be used as it is not
possible to optimize for speed and size at the same time. It is also not possible to use
preprocessor macros embedded in this pragma directive. Any such macro will not be
expanded by the preprocessor.
AFE1_AFE2-1:1
Pragma directives
Note: If you use the #pragma optimize directive to specify an optimization level that
is higher than the optimization level you specify using a compiler option, the pragma
directive is ignored.
#pragma optimize=size
int BigAndSeldomUsed()
{
/* Do something here. */
}
pack
Syntax #pragma pack(n)
#pragma pack()
#pragma pack({push|pop}[,name] [,n])
Parameters
n Sets an optional structure alignment—one of: 1, 2, 4, 8, or 16
Empty list Restores the structure alignment to default
push Sets a temporary structure alignment
pop Restores the structure alignment from a temporarily pushed
alignment
name An optional pushed or popped alignment label
Description Use this pragma directive to specify the maximum alignment of struct and union
members.
The #pragma pack directive affects declarations of structures following the pragma
directive to the next #pragma pack or the end of the compilation unit.
Note: This can result in significantly larger and slower code when accessing members
of the structure.
347
AFE1_AFE2-1:1
Descriptions of pragma directives
__printf_args
Syntax #pragma __printf_args
Description Use this pragma directive on a function with a printf-style format string. For any call to
that function, the compiler verifies that the argument to each conversion specifier, for
example %d, is syntactically correct.
You cannot use this pragma directive on functions that are members of an overload set
with more than one member.
public_equ
Syntax #pragma public_equ="symbol",value
Parameters
symbol The name of the assembler symbol to be defined (string).
value The value of the defined assembler symbol (integer constant
expression).
Description Use this pragma directive to define a public assembler label and give it a value.
required
Syntax #pragma required=symbol
Parameters
symbol Any statically linked function or variable.
AFE1_AFE2-1:1
Pragma directives
Description Use this pragma directive to ensure that a symbol which is needed by a second symbol
is included in the linked output. The directive must be placed immediately before the
second symbol.
Use the directive if the requirement for a symbol is not otherwise visible in the
application, for example, if a variable is only referenced indirectly through the segment
it resides in.
#pragma required=copyright
int main()
{
/* Do something here. */
}
Even if the copyright string is not used by the application, it will still be included by the
linker and available in the output.
rtmodel
Syntax #pragma rtmodel="key","value"
Parameters
"key" A text string that specifies the runtime model attribute.
"value" A text string that specifies the value of the runtime model
attribute. Using the special value * is equivalent to not
defining the attribute at all.
Description Use this pragma directive to add a runtime model attribute to a module, which can be
used by the linker to check consistency between modules.
This pragma directive is useful for enforcing consistency between modules. All modules
that are linked together and define the same runtime attribute key must have the same
value for the corresponding key, or the special value *. It can, however, be useful to state
explicitly that the module can handle any runtime model.
A module can have several runtime model definitions.
Note: The predefined compiler runtime model attributes start with a double underscore.
To avoid confusion, this style must not be used in the user-defined attributes.
349
AFE1_AFE2-1:1
Descriptions of pragma directives
The linker will generate an error if a module that contains this definition is linked with
a module that does not have the corresponding runtime model attributes defined.
__scanf_args
Syntax #pragma __scanf_args
Description Use this pragma directive on a function with a scanf-style format string. For any call to
that function, the compiler verifies that the argument to each conversion specifier, for
example %d, is syntactically correct.
You cannot use this pragma directive on functions that are members of an overload set
with more than one member.
int GetNumber()
{
int nr;
scanf("%d", &nr); /* Compiler checks that
the argument is a
pointer to an integer */
return nr;
}
segment
Syntax #pragma segment="NAME" [__memoryattribute]
alias
#pragma section="NAME" [__memoryattribute] [align]
Parameters
NAME The name of the segment.
__memoryattribute An optional memory attribute identifying the memory the
segment will be placed in; if not specified, default memory is
used.
AFE1_AFE2-1:1
Pragma directives
Description Use this pragma directive to define a segment name that can be used by the segment
operators __segment_begin, __segment_end, and __segment_size. All segment
declarations for a specific segment must have the same memory type attribute and
alignment.
The align and the__memoryattribute parameters are only relevant when used
together with the segment operators __segment_begin, __segment_end, and
__segment_size. If you consider using align on an individual variable to achieve a
higher alignment, you must instead use the #pragma data_alignment directive.
If an optional memory attribute is used, the return type of the segment operators
__segment_begin and __segment_end is:
void __memoryattribute *.
See also Dedicated segment operators, page 201 and the chapters Linking overview and Linking
your application.
STDC CX_LIMITED_RANGE
Syntax #pragma STDC CX_LIMITED_RANGE {ON|OFF|DEFAULT}
Parameters
ON Normal complex mathematic formulas can be used.
OFF Normal complex mathematic formulas cannot be used.
DEFAULT Sets the default behavior, that is OFF.
Description Use this pragma directive to specify that the compiler can use the normal complex
mathematic formulas for * (multiplication), / (division), and abs.
Note: This directive is required by Standard C. The directive is recognized but has no
effect in the compiler.
351
AFE1_AFE2-1:1
Descriptions of pragma directives
STDC FENV_ACCESS
Syntax #pragma STDC FENV_ACCESS {ON|OFF|DEFAULT}
Parameters
ON Source code accesses the floating-point environment.
Note: This argument is not supported by the compiler.
OFF Source code does not access the floating-point environment.
DEFAULT Sets the default behavior, that is OFF.
Description Use this pragma directive to specify whether your source code accesses the
floating-point environment or not.
Note: This directive is required by Standard C.
STDC FP_CONTRACT
Syntax #pragma STDC FP_CONTRACT {ON|OFF|DEFAULT}
Parameters
ON The compiler is allowed to contract floating-point
expressions.
OFF The compiler is not allowed to contract floating-point
expressions.
Note: This argument is not supported by the compiler.
DEFAULT Sets the default behavior, that is ON.
Description Use this pragma directive to specify whether the compiler is allowed to contract
floating-point expressions or not. This directive is required by Standard C.
type_attribute
Syntax #pragma type_attribute=type_attr[ type_attr...]
Parameters For information about type attributes that can be used with this pragma directive, see
Type attributes, page 317.
AFE1_AFE2-1:1
Pragma directives
Description Use this pragma directive to specify IAR-specific type attributes, which are not part of
Standard C. Note however, that a given type attribute might not be applicable to all kind
of objects.
This directive affects the declaration of the identifier, the next variable, or the next
function that follows immediately after the pragma directive.
Example In this example, an int object with the memory attribute __data16 is defined:
#pragma type_attribute=__data16
int x;
unroll
Syntax #pragma unroll=n
Parameters
n The number of loop bodies in the unrolled loop, a constant
integer. #pragma unroll = 1 will prevent the unrolling of
a loop.
Description Use this pragma directive to specify that the loop following immediately after the
directive should be unrolled and that the unrolled loop should have n copies of the loop
body. The pragma directive can only be placed immediately before a for, do, or while
loop, whose number of iterations can be determined at compile time.
Normally, unrolling is most effective for relatively small loops. However, in some cases,
unrolling larger loops can be beneficial if it exposes opportunities for further
optimizations between the unrolled loop iterations, for example, common subexpression
elimination or dead code elimination.
The #pragma unroll directive can be used to force a loop to be unrolled if the
unrolling heuristics are not aggressive enough. The pragma directive can also be used to
reduce the aggressiveness of the unrolling heuristics.
353
AFE1_AFE2-1:1
Descriptions of pragma directives
vector
Syntax #pragma vector=vector1[, vector2, vector3, ...]
Parameters
vectorN The vector number(s) of an interrupt or trap function.
Description Use this pragma directive to specify the vector(s) of an interrupt or trap function whose
declaration follows the pragma directive. Note that several vectors can be defined for
each function.
This pragma directive cannot be used if you have specified the --ropi option.
weak
Syntax #pragma weak symbol1[=symbol2]
Parameters
symbol1 A function or variable with external linkage.
symbol2 A defined function or variable.
AFE1_AFE2-1:1
Intrinsic functions
● Summary of intrinsic functions
355
AFE1_AFE2-1:1
Summary of intrinsic functions
AFE1_AFE2-1:1
Intrinsic functions
__bcd_add_type
Syntax unsigned type __bcd_add_type(unsigned type x, unsigned type y);
where:
Description Performs a binary coded decimal addition. The parameters and the return value are
represented as binary coded decimal (BCD) numbers, that is when a hexadecimal
number (0x19) is used for representing the decimal number 19. The following functions
are supported:
Function Return value
__bcd_add_short Returns the sum of the two short parameters. The
parameters and the return value are represented as four-digit
BCD numbers.
__bcd_add_long Returns the sum of the two long parameters. The parameters
and the return value are represented as eight-digit BCD
numbers.
__bcd_add_long_long Returns the sum of the two long long parameters. The
parameters and the return value are represented as
sixteen-digit BCD numbers.
Table 40: Functions for binary coded decimal operations
Example /* c = 0x19 */
c = __bcd_add_short(c, 0x01);
/* c = 0x20 */
__bic_SR_register
Syntax void __bic_SR_register(unsigned short);
Description Clears bits in the processor status register. The function takes an integer as its argument,
that is, a bit mask with the bits to be cleared.
357
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__bic_SR_register_on_exit
Syntax void __bic_SR_register_on_exit(unsigned short);
Description Clears bits in the processor status register when an interrupt or monitor function returns.
The function takes an integer as its argument, that is, a bit mask with the bits to be
cleared.
This intrinsic function is only available in interrupt and monitor functions.
__bis_GIE_interrupt_state
Syntax void __bis_GIE_interrupt_state(__istate_t)
Description Sets the GIE bit of the processor status register, if set in the state.
__bis_SR_register
Syntax void __bis_SR_register(unsigned short);
Description Sets bits in the status register. The function takes an integer literal as its argument, that
is, a bit mask with the bits to be set.
__bis_SR_register_on_exit
Syntax void __bis_SR_register_on_exit(unsigned short);
Description Sets bits in the processor status register when an interrupt or monitor function returns.
The function takes an integer literal as its argument, that is, a bit mask with the bits to
be set.
This intrinsic function is only available in interrupt and monitor functions.
__code_distance
Syntax long __code_distance(void);
AFE1_AFE2-1:1
Intrinsic functions
Description Returns the number of bytes between the placement of code in memory and the position
it was linked for. For non-position-independent code, the function returns 0.
The actual start address of a position-independent segment MY_SEG is
(char *) __segment_begin("MY_SEG") + __code_distance().
See also Position-independent code and read-only data, page 80 and Dedicated segment
operators, page 201
__data16_read_addr
Syntax unsigned long __data16_read_addr(unsigned short address);
where:
Description Reads data from a 20-bit SFR register located at the given 16-bit address. This intrinsic
function is only useful on devices based on the MSP430X architecture.
In the Small data model, and if interrupts are not configured to save all 20 bits of the
registers they are using, interrupts must be disabled when you use this intrinsic function.
__data16_write_addr
Syntax void __data16_write_addr(unsigned short address,
unsigned long data);
where:
Description Writes a value to a 20-bit SFR register located at the given 16-bit address. This intrinsic
function is only useful on devices based on the MSP430X architecture.
In the Small data model, and if interrupts are not configured to save all 20 bits of the
registers they are using, interrupts must be disabled when you use this intrinsic function.
359
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__data20_longjmp
Syntax void __data20_longjmp(__JMP_BUF_ELEMENT_TYPE__ __data20 *, int);
Description Like the standard function longjmp, but allows you to place the jump buffer in data20
memory.
__data20_read_type
Syntax unsigned type __data20_read_type(unsigned long address);
where:
Description Reads data from the MSP430X full 1-Mbyte memory area. This intrinsic function is
intended to be used in the Small data model. In the Medium and Large data models it is
recommended to use __data20 variables and pointers.
The following functions are supported:
Function Operation size Alignment
unsigned char __data20_read_char 1 byte 1
unsigned short __data20_read_short 2 bytes 2
unsigned long __data20_read_long 4 bytes 2
Table 41: Functions for reading data that has a 20-bit address
Note: In the Small data model, and if interrupts are not configured to save all 20 bits of
the registers they are using, interrupts must be disabled when you use this intrinsic
function.
__data20_setjmp
Syntax int __data20_setjmp(__JMP_BUF_ELEMENT_TYPE__ __data20 *);
Description Like the standard function setjmp, but allows the jump buffer to be placed in data20
memory.
AFE1_AFE2-1:1
Intrinsic functions
__data20_write_type
Syntax void __data20_write_type(unsigned long address, unsigned type);
where:
Description Writes data to the MSP430X full 1-Mbyte memory area. This intrinsic function is
intended to be used in the Small data model. In the Medium and Large data models it is
recommended to use __data20 variables and pointers.
The following functions are supported:
Function Operation size Alignment
unsigned char __data20_write_char 1 byte 1
unsigned short __data20_write_short 2 bytes 2
unsigned long __data20_write_long 4 bytes 2
Table 42: Functions for writing data that has a 20-bit address
Note: In the Small data model, and if interrupts are not configured to save all 20 bits of
the registers they are using, interrupts must be disabled when you use this intrinsic
function.
__delay_cycles
Syntax void __delay_cycles(unsigned long cycles);
Parameters
cycles The time delay in number of cycles. This must be a constant.
Description Inserts assembler instructions that delay the execution the number of specified clock
cycles, with a minimum of code.
__disable_interrupt
Syntax void __disable_interrupt(void);
361
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__enable_interrupt
Syntax void __enable_interrupt(void);
__even_in_range
Syntax unsigned short __even_in_range(unsigned short value,
unsigned short upper_limit);
Parameters
value The switch expression
upper_limit The last value in the allowed range
Description Instructs the compiler to rely on the specified value being even and within the specified
range. The code will be generated accordingly and will only work if the requirement is
fulfilled.
This intrinsic function can be used for achieving optimal code for switch statements
where you know that the only values possible are even values within a given range, for
example an interrupt service routine for an Interrupt Vector Generator interrupt.
__get_interrupt_state
Syntax __istate_t __get_interrupt_state(void);
Description Returns the global interrupt state. The return value can be used as an argument to the
__set_interrupt_state intrinsic function, which will restore the interrupt state.
AFE1_AFE2-1:1
Intrinsic functions
void CriticalFn()
{
__istate_t s = __get_interrupt_state();
__disable_interrupt();
/* Do something here. */
__set_interrupt_state(s);
}
__get_R4_register
Syntax unsigned short __get_R4_register(void);
Description Returns the value of the R4 register. This intrinsic function is only available when the
register is locked.
__get_R5_register
Syntax unsigned short __get_R5_register(void);
Description Returns the value of the R5 register. This intrinsic function is only available when the
register is locked.
__get_SP_register
Syntax unsigned short __get_SP_register(void);
363
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__get_SR_register
Syntax unsigned short __get_SR_register(void);
__get_SR_register_on_exit
Syntax unsigned short __get_SR_register_on_exit(void);
Description Returns the value that the processor status register SR will have when the current
interrupt or monitor function returns.
This intrinsic function is only available in interrupt and monitor functions.
__low_power_mode_n
Syntax void __low_power_mode_n(void);
Description Enters a MSP430 low power mode, where n can be one of 0–4. This also enables global
interrupts by setting the GIE bit in the status register.
__low_power_mode_off_on_exit
Syntax void __low_power_mode_off_on_exit(void);
Description Turns off the low power mode when a monitor or interrupt function returns. This
intrinsic function is only available in interrupt and monitor functions.
__no_operation
Syntax void __no_operation(void);
__op_code
Syntax void __op_code(unsigned short);
AFE1_AFE2-1:1
Intrinsic functions
Description Emits the 16-bit value into the instruction stream for the current function by inserting a
DC16 constant.
__saturated_add_signed_type
Syntax __saturated_add_signed_type(signed type, signed type);
where type can be one of char, short, long, and long long
Description Performs a saturated addition. When the mathematical result is outside the range of the
destination type, the result is the smallest or largest value that the type can hold.
__saturated_add_unsigned_type
Syntax __saturated_add_unsigned_type(unsigned type, unsigned type);
where type can be one of char, short, long, and long long
Description Performs a saturated addition. When the mathematical result is outside the range of the
destination type, the result is the smallest or largest value that the type can hold.
__saturated_sub_signed_type
Syntax __saturated_sub_signed_type(signed type, signed type);
where type can be one of char, short, long, and long long
Description Performs a saturated subtraction. When the mathematical result is outside the range of
the destination type, the result is the smallest or largest value that the type can hold.
__saturated_sub_unsigned_type
Syntax __saturated_sub_unsigned_type(unsigned type, unsigned type);
where type can be one of char, short, long, and long long
365
AFE1_AFE2-1:1
Descriptions of intrinsic functions
Description Performs a saturated subtraction. When the mathematical result is outside the range of
the destination type, the result is the smallest or largest value that the type can hold.
__set_interrupt_state
Syntax void __set_interrupt_state(__istate_t);
__set_R4_register
Syntax void __set_R4_register(unsigned short);
Description Writes a specific value to the R4 register. This intrinsic function is only available when
R4 is locked.
__set_R5_register
Syntax void __set_R5_register(unsigned short);
Description Writes a specific value to the R5 register. This intrinsic function is only available when
R5 is locked.
AFE1_AFE2-1:1
Intrinsic functions
__set_SP_register
Syntax void __set_SP_register(unsigned short);
Description Writes a specific value to the SP stack pointer register. A warning message is issued if
the compiler has used the stack in any way at the location where this intrinsic function
is used.
__swap_bytes
Syntax unsigned short __swap_bytes(unsigned short);
Description Inserts an SWPB instruction and returns the argument with the upper and lower parts
interchanged.
Example __swap_bytes(0x1234)
returns 0x3412.
367
AFE1_AFE2-1:1
Descriptions of intrinsic functions
AFE1_AFE2-1:1
The preprocessor
● Overview of the preprocessor
Note: Backslashes can also be used—use one in include file paths and two in source
code strings.
369
AFE1_AFE2-1:1
Description of predefined preprocessor symbols
__BASE_FILE__
Description A string that identifies the name of the base source file (that is, not the header file), being
compiled.
__BUILD_NUMBER__
Description A unique integer that identifies the build number of the compiler currently in use. The
build number does not necessarily increase with a compiler that is released later.
__CODE_MODEL__
Description An integer that identifies the code model in use. The value reflects the setting of the
--code_model option and is defined to __CODE_MODEL_SMALL__ or
__CODE_MODEL_LARGE__. These symbolic names can be used when testing the
__CODE_MODEL__ symbol.
__CORE__
Description An integer that identifies the chip core in use. The value reflects the setting of the
--core option and is defined to __430__ for the MSP430 architecture and to
__430X__ for the MSP430X architecture. These symbolic names can be used when
testing the __CORE__ symbol.
__COUNTER__
Description A macro that expands to a new integer each time it is expanded, starting at zero (0) and
counting up.
__cplusplus
Description An integer which is defined when the compiler runs in any of the C++ modes, otherwise
it is undefined. When defined, its value is 199711L. This symbol can be used with
AFE1_AFE2-1:1
The preprocessor
#ifdef to detect whether the compiler accepts C++ code. It is particularly useful when
creating header files that are to be shared by C and C++ code.
This symbol is required by Standard C.
__DATA_MODEL__
Description An integer that identifies the data model in use. The value reflects the setting of the
--data_model option and is defined to __DATA_MODEL_SMALL__,
__DATA_MODEL_MEDIUM__, or __DATA_MODEL_LARGE__. These symbolic names can
be used when testing the __DATA_MODEL__ symbol.
__DATE__
Description A string that identifies the date of compilation, which is returned in the form "Mmm dd
yyyy", for example, "Oct 30 2018".
__embedded_cplusplus
Description An integer which is defined to 1 when the compiler runs in any of the C++ modes,
otherwise the symbol is undefined. This symbol can be used with #ifdef to detect
whether the compiler accepts C++ code. It is particularly useful when creating header
files that are to be shared by C and C++ code.
This symbol is required by Standard C.
__FILE__
Description A string that identifies the name of the file being compiled, which can be both the base
source file and any included header file.
This symbol is required by Standard C.
371
AFE1_AFE2-1:1
Description of predefined preprocessor symbols
__func__
Description A predefined string identifier that is initialized with the name of the function in which
the symbol is used. This is useful for assertions and other trace utilities. The symbol
requires that language extensions are enabled.
This symbol is required by Standard C.
__FUNCTION__
Description A predefined string identifier that is initialized with the name of the function in which
the symbol is used, similar to char _FUNCTION_[]="main"; if used in main(). This
is useful for assertions and other trace utilities. The symbol requires that language
extensions are enabled.
__IAR_SYSTEMS_ICC__
Description An integer that identifies the IAR compiler platform. The current value is 8—the
number could be higher in a future version of the product. This symbol can be tested
with #ifdef to detect whether the code was compiled by a compiler from IAR Systems.
__ICC430__
Description An integer that is set to 1 when the code is compiled with the IAR C/C++ Compiler for
MSP430.
__LINE__
Description An integer that identifies the current source line number of the file being compiled,
which can be both the base source file and any included header file.
This symbol is required by Standard C.
__POSITION_INDEPENDENT_CODE__
Description An integer that is set to 1 when the code is compiled with the option --ropi.
AFE1_AFE2-1:1
The preprocessor
__PRETTY_FUNCTION__
Description A predefined string identifier that is initialized with the function name, including
parameter types and return type, of the function in which the symbol is used, for
example, "void func(char)". This symbol is useful for assertions and other trace
utilities. The symbol requires that language extensions are enabled.
__REGISTER_MODEL__
Description An integer that equals one of the following: __REGISTER_MODEL_REG16__ (for
MSP430 and MSP430X in the Small data model) or __REGISTER_MODEL_REG20__
(for MSP430X in the Medium and Large data models).
__REGISTER_R4__
Description An integer that identifies the use of register R4. The value reflects the setting of the
--lock_r4 and --regvar_r4 options and is defined to __REGISTER_FREE__,
__REGISTER_LOCKED__, or __REGISTER_REGVAR__.
__REGISTER_R5__
Description An integer that identifies the use of register R5. The value reflects the setting of the
--lock_r5 and --regvar_r5 options and is defined to __REGISTER_FREE__,
__REGISTER_LOCKED__, or __REGISTER_REGVAR__.
__ROPI__
Description An integer that is set to 1 when the code is compiled with the option --ropi.
__STDC__
Description An integer that is set to 1, which means the compiler adheres to Standard C. This symbol
can be tested with #ifdef to detect whether the compiler in use adheres to Standard C.*
This symbol is required by Standard C.
373
AFE1_AFE2-1:1
Descriptions of miscellaneous preprocessor extensions
__STDC_VERSION__
Description An integer that identifies the version of the C standard in use. The symbol expands to
199901L,unless the --c89 compiler option is used in which case the symbol expands
to 199409L. This symbol does not apply in EC++ mode.
This symbol is required by Standard C.
__SUBVERSION__
Description An integer that identifies the subversion number of the compiler version number, for
example 3 in 1.2.3.4.
__TIME__
Description A string that identifies the time of compilation in the form "hh:mm:ss".
This symbol is required by Standard C.
__TIMESTAMP__
Description A string constant that identifies the date and time of the last modification of the current
source file. The format of the string is the same as that used by the asctime standard
function (in other words, "Tue Sep 16 13:03:52 2014").
__VER__
Description An integer that identifies the version number of the IAR compiler in use. The value of
the number is calculated in this way: (100 * the major version number + the
minor version number). For example, for compiler version 3.34, 3 is the major
version number and 34 is the minor version number. Hence, the value of __VER__ is
334.
AFE1_AFE2-1:1
The preprocessor
NDEBUG
Description This preprocessor symbol determines whether any assert macros you have written in
your application shall be included or not in the built application.
If this symbol is not defined, all assert macros are evaluated. If the symbol is defined,
all assert macros are excluded from the compilation. In other words, if the symbol is:
● defined, the assert code will not be included
● not defined, the assert code will be included
This means that if you write any assert code and build your application, you should
define this symbol to exclude the assert code from the final application.
Note: The assert macro is defined in the assert.h standard include file.
In the IDE, the NDEBUG symbol is automatically defined if you build your application in
the Release build configuration.
#warning message
Syntax #warning message
Description Use this preprocessor directive to produce messages. Typically, this is useful for
assertions and other trace utilities, similar to the way the Standard C #error directive
is used. This directive is not recognized when the --strict compiler option is used.
375
AFE1_AFE2-1:1
Descriptions of miscellaneous preprocessor extensions
AFE1_AFE2-1:1
C/C++ standard library
functions
● C/C++ standard library overview
For detailed reference information about the library functions, see the online
help system.
377
AFE1_AFE2-1:1
C/C++ standard library overview
HEADER FILES
Your application program gains access to library definitions through header files, which
it incorporates using the #include directive. The definitions are divided into several
different header files, each covering a particular functional area, letting you include just
those that are required.
It is essential to include the appropriate header file before making any reference to its
definitions. Failure to do so can cause the call to fail during execution, or generate error
or warning messages at compile time or link time.
To use any of these more accurate versions, use the -e linker option.
REENTRANCY
A function that can be simultaneously invoked in the main application and in any
number of interrupts is reentrant. A library function that uses statically allocated data is
therefore not reentrant.
Most parts of the DLIB runtime environment are reentrant, but the following functions
and parts are not reentrant because they need static data:
● Heap functions—malloc, free, realloc, calloc, etc. and the C++ operators
new and delete
● Locale functions—localeconv, setlocale
● Multibyte functions—mblen, mbrlen, mbrtowc, mbsrtowc, mbtowc, wcrtomb,
wcsrtomb, wctomb
AFE1_AFE2-1:1
C/C++ standard library functions
For the CLIB library, the qsort function and functions that use files in some way are
non-reentrant. This includes printf, scanf, getchar, and putchar. However, the
functions sprintf and sscanf are reentrant.
Functions that can set errno are not reentrant, because an errno value resulting from
one of these functions can be destroyed by a subsequent use of the function before it is
read. This applies to math and string conversion functions, among others.
Remedies for this are:
● Do not use non-reentrant functions in interrupt service routines
● Guard calls to a non-reentrant function by a mutex, or a secure region, etc.
379
AFE1_AFE2-1:1
DLIB runtime environment—implementation details
In addition, the DLIB runtime environment includes some added C functionality, see
Added C functionality, page 383.
C HEADER FILES
This section lists the C header files specific to the DLIB runtime environment. Header
files may additionally contain target-specific definitions; these are documented in the
chapter Using C.
This table lists the C header files:
Header file Usage
assert.h Enforcing assertions when functions execute
complex.h Computing common complex mathematical functions
ctype.h Classifying characters
errno.h Testing error codes reported by library functions
fenv.h Floating-point exception flags
float.h Testing floating-point type properties
inttypes.h Defining formatters for all types defined in stdint.h
iso646.h Using Amendment 1—iso646.h standard header
limits.h Testing integer type properties
locale.h Adapting to different cultural conventions
math.h Computing common mathematical functions
setjmp.h Executing non-local goto statements
signal.h Controlling various exceptional conditions
stdarg.h Accessing a varying number of arguments
stdbool.h Adds support for the bool data type in C.
stddef.h Defining several useful types and macros
stdint.h Providing integer characteristics
stdio.h Performing input and output
stdlib.h Performing a variety of operations
string.h Manipulating several kinds of strings
tgmath.h Type-generic mathematical functions
time.h Converting between various time and date formats
uchar.h Unicode functionality (IAR extension to Standard C)
wchar.h Support for wide characters
Table 43: Traditional Standard C header files—DLIB
AFE1_AFE2-1:1
C/C++ standard library functions
381
AFE1_AFE2-1:1
DLIB runtime environment—implementation details
AFE1_AFE2-1:1
C/C++ standard library functions
ADDED C FUNCTIONALITY
The DLIB runtime environment includes some added C functionality.
The following include files provide these features:
● fenv.h
● stdio.h
● stdlib.h
● string.h
● time.h
fenv.h
In fenv.h, trap handling support for floating-point numbers is defined with the
functions fegettrapenable and fegettrapdisable.
383
AFE1_AFE2-1:1
DLIB runtime environment—implementation details
stdio.h
These functions provide additional I/O functionality:
string.h
These are the additional functions defined in string.h:
time.h
There are two interfaces for using time_t and the associated functions time, ctime,
difftime, gmtime, localtime, and mktime:
● The 32-bit interface supports years from 1900 up to 2035 and uses a 32-bit integer
for time_t. The type and function have names like __time32_t, __time32, etc.
This variant is mainly available for backwards compatibility.
● The 64-bit interface supports years from -9999 up to 9999 and uses a signed
long long for time_t. The type and function have names like __time64_t,
__time64, etc.
AFE1_AFE2-1:1
C/C++ standard library functions
the 32-bit variants. However, to explicitly redirect them to their 64-bit variants, define
_DLIB_TIME_USES_64 in front of the inclusion of time.h or ctime.
__assignment_by_bitwise_copy_allowed
This symbol is used as a memory attribute internally by the compiler, and might have
to be used as an argument in certain templates.
__constrange()
Determines the allowed range for a parameter to an intrinsic function and that the
parameter must be of type const.
__construction_by_bitwise_copy_allowed
These symbols determine properties for class objects and they function like the sizeof
operator. The symbols are true when a class, base class, or member (recursively) has a
user-defined constructor or destructor, respectively.
__memory_of
Determines the class memory. A class memory determines which memory a class
object can reside in. This symbol can only occur in class definitions as a class memory.
Note: The symbols are reserved and should only be used by the library.
Use the compiler option --predef_macros to determine the value for any predefined
symbols.
385
AFE1_AFE2-1:1
CLIB runtime environment—implementation details
* The functions isxxx, toupper, and tolower declared in the header file ctype.h
evaluate their argument more than once. This is not according to the ISO/ANSI
standard.
AFE1_AFE2-1:1
Segment reference
● Summary of segments
● Descriptions of segments
For more information about placement of segments, see the chapter Linking
your application.
Summary of segments
The table below lists the segments that are available in the compiler:
Segment Description
BSLSIGNATURE Holds BSL configuration data recognized by the device.
CHECKSUM Holds the checksum generated by the linker.
CODE Holds the program code.
CODE_I Holds code declared __ramfunc.
CODE_ID Holds the code copied to CODE_I at startup.
CODE_PAD Holds padding NOP instructions between the CODE and MPU_B2
segments.
CODE16 Holds the program code in the Small code model.
CSTACK Holds the stack used by C or C++ programs.
CSTART Holds the startup code.
DATA16_AC Holds absolute located constant data that has the memory attribute
__data16.
DATA16_AN Holds absolute located __no_init data that has the memory
attribute __data16.
DATA16_C Holds constant data that has the memory attribute __data16.
DATA16_HEAP Holds the __data16 heap.
DATA16_I Holds static and global initialized variables that have the memory
attribute __data16.
DATA16_ID Holds initial values for static and global initialized variables in
DATA16_I.
Table 48: Segment summary
387
AFE1_AFE2-1:1
Summary of segments
Segment Description
DATA16_N Holds __no_init static and global variables that have the memory
attribute __data16.
DATA16_P Holds variables that are defined with the __persistent keyword and
that have the __data16 memory attribute.
DATA16_Z Holds zero-initialized static and global variables that have the memory
attribute __data16.
DATA20_AC Holds absolute located constant data that has the memory attribute
__data20.
DATA20_AN Holds absolute located __no_init data that has the
memory attribute __data20.
DATA20_C Holds constant data that has the memory attribute __data20.
DATA20_HEAP Holds the __data20 heap.
DATA20_I Holds static and global initialized variables that have the memory
attribute __data20.
DATA20_ID Holds initial values for static and global initialized variables in
DATA20_I.
DATA20_N Holds __no_init static and global variables that have the memory
attribute __data20.
DATA20_P Holds variables that are defined with the __persistent keyword and
that have the __data20 memory attribute.
DATA20_Z Holds zero-initialized static and global variables that have the memory
attribute __data20.
DIFUNCT Holds pointers to code, typically C++ constructors, that should be
executed by the system startup code before main is called.
INFO Holds data to be placed in the MSP430 information memory.
INFOA Holds data to be placed in bank A of the MSP430 information memory.
INFOB Holds data to be placed in bank B of the MSP430 information memory.
INFOC Holds data to be placed in bank C of the MSP430 information memory.
INFOD Holds data to be placed in bank D of the MSP430 information memory.
INTVEC Holds the interrupt vector.
IPE_B1 Defines the start of the IPE address range.
IPE_B2 Defines the end of the IPE address range.
IPECODE16 Holds code inside the IPE address range.
IPEDATA16_C Holds constant data inside the IPE address range.
Table 48: Segment summary (Continued)
AFE1_AFE2-1:1
Segment reference
Segment Description
IPEDATA16_N Holds writable __no_init data inside the IPE address range.
IPESIGNATURE Holds IPE configuration data recognized by the device.
ISR_CODE Holds interrupt functions when compiling for the MSP430X architecture.
JTAGSIGNATURE Holds JTAG configuration data recognized by the device.
MPU_B1 Defines the border between the first and second MPU ranges.
MPU_B2 Defines the border between the second and third MPU ranges.
REGVAR_AN Holds __regvar data.
RESET Holds the reset vector.
SIGNATURE Holds configuration data recognized by the device.
This segment is deprecated but kept for backward compatibility.
TLS16_I Holds thread-local static and global initialized variables used by the main
thread.
TLS16_ID Holds initial values for thread-local static and global variables in
TLS16_I.
Table 48: Segment summary (Continued)
Descriptions of segments
This section gives reference information about each segment.
The segments are placed in memory by the segment placement linker directives -Z and
-P, for sequential and packed placement, respectively. Some segments cannot use
packed placement, as their contents must be continuous. For information about these
directives, see Using the -Z command for sequential placement, page 103 and Using the
-P command for packed placement, page 103, respectively.
For each segment, the segment memory type is specified, which indicates in which type
of memory the segment should be placed. See Segment memory type, page 86.
For information about how to define segments in the linker configuration file, see
Linking your application, page 101.
For more information about the extended keywords mentioned here, see the chapter
Extended keywords.
BSLSIGNATURE
Description Holds BSL configuration data recognized by the device.
389
AFE1_AFE2-1:1
Descriptions of segments
CHECKSUM
Description Holds the checksum bytes generated by the linker. This segment also holds the
__checksum symbol, unless it is explicitly defined elsewhere. Note that the size of this
segment is affected by the linker option -J.
CODE
Description Holds program code, except the code for system initialization, unless the Small code
model is used (MSP430X only). For MSP430, this segment also holds interrupt code.
CODE_I
Description Holds program code declared __ramfunc. This code will be executed in RAM. The
code is copied from CODE_ID during initialization.
AFE1_AFE2-1:1
Segment reference
CODE_ID
Description This is the permanent storage of program code declared __ramfunc. This code will be
executed in RAM. The code is copied to CODE_I during initialization.
CODE_PAD
Description Holds padding NOP instructions between the CODE and MPU_B2 segments, to prevent the
instruction prefetch mechanism from violating MPU access restrictions.
CODE16
Description Holds program code, except the code for system initialization, in the Small code model
(MSP430X only).
CSTACK
Description Holds the internal data stack.
391
AFE1_AFE2-1:1
Descriptions of segments
CSTART
Description Holds the startup code.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
DATA16_AC
Description Holds absolute located constant data that has the memory attribute __data16.
Absolute located means being placed at an absolute location using the @ operator or the
#pragma location directive. Because the location is known, this segment does not
need to be specified in the linker configuration file.
DATA16_AN
Description Holds absolute located __no_init data that has the memory attribute __data16.
Absolute located means being placed at an absolute location using the @ operator or the
#pragma location directive. Because the location is known, this segment does not
need to be specified in the linker configuration file.
DATA16_C
Description Holds constant data that has the memory attribute __data16. This can include constant
variables, string and aggregate literals, etc.
AFE1_AFE2-1:1
Segment reference
DATA16_HEAP
Description Holds the heap used for dynamically allocated data that has the memory attribute
__data16, in other words data allocated by data16_malloc and data16_free, and in
C++, new and delete.
See also Setting up heap memory, page 106 and New and Delete operators, page 211.
DATA16_I
Description Holds static and global initialized variables that have the memory attribute __data16
and that are initialized by copying from the segment DATA16_ID at application startup.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
DATA16_ID
Description Holds initial values for static and global initialized variables that have the memory
attribute __data16. These values are copied from DATA16_ID to DATA16_I at
application startup.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
393
AFE1_AFE2-1:1
Descriptions of segments
DATA16_N
Description Holds static and global __no_init variables that have the memory attribute __data16.
DATA16_P
Description Holds static and global variables that are defined with the __persistent keyword and
that have the __data16 memory attribute. These variables will only be initialized, for
example, by a code downloader, and not by cstartup.
See also
DATA16_Z
Description Holds zero-initialized static and global variables that have the memory attribute
__data16. The contents of this segment is declared by the system startup code.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
AFE1_AFE2-1:1
Segment reference
DATA20_AC
Description Holds absolute located constant data that has the memory attribute __data20.
Absolute located means being placed at an absolute location using the @ operator or the
#pragma location directive. Because the location is known, this segment does not
need to be specified in the linker configuration file.
Note: The compiler requires that no data is placed in the address range
0x10000-0x1003F.
DATA20_AN
Description Holds absolute located __no_init data that has the memory attribute __data20.
Absolute located means being placed at an absolute location using the @ operator or the
#pragma location directive. Because the location is known, this segment does not
need to be specified in the linker configuration file.
Note: The compiler requires that no data is placed in the address range
0x10000-0x1003F.
DATA20_C
Description Holds constant data that has the memory attribute __data20. This can include constant
variables, string and aggregate literals, etc.
This segment is only available if you are using MSP430X.
395
AFE1_AFE2-1:1
Descriptions of segments
DATA20_HEAP
Description Holds the heap used for dynamically allocated data that has the memory attribute
__data20, in other words data allocated by data20_malloc and data20_free, and
in C++, new and delete.
This segment is only available if you are using MSP430X.
See also Setting up heap memory, page 106 and New and Delete operators, page 211.
DATA20_I
Description Holds static and global initialized variables that have the memory attribute __data20
and that are initialized by copying from the segment DATA20_ID at application startup.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
This segment is only available if you are using MSP430X.
DATA20_ID
Description Holds initial values for static and global variables that have the memory attribute
__data20. These values are copied from DATA20_ID to DATA20_I at application
startup.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
This segment is only available if you are using MSP430X.
AFE1_AFE2-1:1
Segment reference
DATA20_N
Description Holds static and global __no_init variables that have the memory attribute
__data20.
DATA20_P
Description Holds static and global variables that are defined with the __persistent keyword and
that have the __data20 memory attribute. These variables will only be initialized, for
example, by a code downloader, and not by cstartup.
This segment is only available if you are using MSP430X.
DATA20_Z
Description Holds zero-initialized static and global variables that have the memory attribute
__data20. The contents of this segment is declared by the system startup code.
397
AFE1_AFE2-1:1
Descriptions of segments
This segment cannot be placed in memory by using the -P directive for packed
placement, because the contents must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
This segment is only available if you are using MSP430X.
DIFUNCT
Description Holds the dynamic initialization vector used by C++.
Memory placement This segment must be placed in the first 64 Kbytes of memory.
INFO
Description Holds data to be placed in the MSP430 information memory. Note that the INFO
segment and the INFOA–INFOD segments overlap.
INFOA
Description Holds data to be placed in bank A of the MSP430 information memory. Note that the
INFOA segment and the INFO segment overlap.
AFE1_AFE2-1:1
Segment reference
INFOB
Description Holds data to be placed in bank B of the MSP430 information memory. Note that the
INFOB segment and the INFO segment overlap.
INFOC
Description Holds data to be placed in bank C of the MSP430 information memory. Note that the
INFOC segment and the INFO segment overlap.
INFOD
Description Holds data to be placed in bank D of the MSP430 information memory. Note that the
INFOD segment and the INFO segment overlap.
INTVEC
Description Holds the interrupt vector table generated by the use of the __interrupt extended
keyword in combination with the #pragma vector directive.
399
AFE1_AFE2-1:1
Descriptions of segments
IPE_B1
Description The start of this segment defines the start of the protected IPE address range. It holds the
IPE control struct which is read by the boot code to initialize the IPE.
IPE_B2
Description The start of this segment defines the end of the protected IPE address range. It only
contains a zero-size code fragment that constrains the alignment of the IPE end address.
IPECODE16
Description Holds code inside the protected IPE address range. Code in this segment can be used for
reading data located inside the protected IPE address range.
AFE1_AFE2-1:1
Segment reference
IPEDATA16_C
Description Holds constants inside the protected IPE address range. Data in this segment can only
be read by code located inside the protected IPE address range.
IPEDATA16_N
Description Holds writable __no_init data inside the protected IPE address range. Data inside this
range can only be read or written by code located inside the protected IPE address range.
IPESIGNATURE
Description Holds IPE configuration data recognized by the device.
ISR_CODE
Description Holds interrupt functions when compiling for the MSP430X architecture. This segment
is not used when compiling for the MSP430 architecture.
401
AFE1_AFE2-1:1
Descriptions of segments
JTAGSIGNATURE
Description Holds JTAG configuration data recognized by the device.
MPU_B1
Description The __iar_430_mpu_init function uses the start of this segment to define the border
between the first and second MPU address ranges. This segment only contains a
zero-size code fragment that constrains the alignment of the MPU border.
MPU_B2
Description The __iar_430_mpu_init function uses the start of this segment to define the border
between the second and third MPU address ranges. This segment only contains a
zero-size code fragment that constrains the alignment of the MPU border.
REGVAR_AN
Description Holds __regvar data.
AFE1_AFE2-1:1
Segment reference
Memory placement This segment is placed in the memory area reserved for registers, and does not occupy
space in the normal memory area.
RESET
Description Holds the reset vector.
SIGNATURE
Description Holds configuration data recognized by the device, such as the JTAG password and the
IPE signature.
Note: This segment is deprecated, but kept for backward compatibility.
TLS16_I
Description Holds thread-local static and global initialized variables used by the main thread,
initialized by copying from the segment TLS16_ID at application startup.
This segment is only used by custom-built runtime libraries configured with thread
support.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the content must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
403
AFE1_AFE2-1:1
Descriptions of segments
TLS16_ID
Description Holds initial values for thread-local static and global variables in the TLS16_I segment
for the main thread, and for each started thread. The main thread is initialized by the
startup code; all other threads are initialized by the embedded operating system.
This segment cannot be placed in memory by using the -P directive for packed
placement, because the content must be continuous. Instead, when you define this
segment in the linker configuration file, the -Z directive must be used.
AFE1_AFE2-1:1
The stack usage control file
● Overview
● Syntactic components
Before you read this chapter, see Stack usage analysis, page 91.
Overview
A stack usage control file consists of a sequence of directives that control stack usage
analysis. You can use C ("/*...*/") and C++ ("//...") comments in these files.
The default filename extension for stack usage control files is suc.
C++ NAMES
You can also use wildcards in function names. "#*" matches any sequence of characters,
and "#?" matches a single character.
Parameters
category See category, page 409
func-spec See func-spec, page 409
Description Specifies that the listed functions are call graph roots. You can optionally specify a call
graph root category. Call graph roots are listed under their category in the Stack Usage
chapter in the linker map file.
405
AFE1_AFE2-1:1
Stack usage control directives
The linker will normally issue a warning for functions needed in the application that are
not call graph roots and which do not appear to be called.
Parameters
expression A boolean expression.
Description You can use the check that directive to compare the results of stack usage analysis
against the sizes of blocks and regions. If the expression evaluates to zero, an error is
emitted.
Three extra operators are available for use only in check that expressions:
maxstack(category) The stack depth of the deepest call chain for any call
graph root function in the category.
totalstack(category) The sum of the stack depths of the deepest call chains
for each call graph root function in the category.
size("SEGMENT") The size of the segment.
exclude directive
Syntax exclude func-spec [, func-spec... ];
Parameters
func-spec See func-spec, page 409
AFE1_AFE2-1:1
The stack usage control file
Description Excludes the specified functions, and call trees originating with them, from stack usage
calculations.
function directive
Syntax [ override ] function [ category ] func-spec : stack-size
[ , call-info... ];
Parameters
category See category, page 409
func-spec See func-spec, page 409
call-info See call-info, page 410
stack-size See stack-size, page 411
Description Specifies what the maximum stack usage is in a function and which other functions that
are called from that function.
Normally, an error is issued if there already is stack usage information for the function,
but if you start with override, the error will be suppressed and the information
supplied in the directive will be used instead of the previous information.
Parameters
func-spec See func-spec, page 409
size See size, page 411
Description Specifies the maximum number of iterations through any of the cycles in the recursion
nest of which the function is a member.
407
AFE1_AFE2-1:1
Stack usage control directives
A recursion nest is a set of cycles in the call graph where each cycle shares at least one
node with another cycle in the nest.
Stack usage analysis will base its result on the max recursion depth multiplied by the
stack usage of the deepest cycle in the nest. If the nest is not entered on a point along
one of the deepest cycles, no stack usage result will be calculated for such calls.
Parameters
func-spec See func-spec, page 409
module-spec See module-spec, page 410
Description When you provide stack usage information for some functions in a module without
stack usage information, the linker warns about functions that are referenced from the
module but not listed as called. This is primarily to help avoid problems with C runtime
routines, calls to which are generated by the compiler, beyond user control.
If there actually is no call to some of these functions, use the no calls from directive
to selectively suppress the warning for the specified functions. You can also disable the
warning entirely (--diag_suppress or
Project>Options>Linker>Diagnostics>Suppress these diagnostics).
Parameters
calling-func See func-spec, page 409
called-func See func-spec, page 409
Description Specifies an exhaustive list of possible destinations for all indirect calls in one function.
Use this for functions which are known to perform indirect calls and where you know
exactly which functions that might be called in this particular application. Consider
AFE1_AFE2-1:1
The stack usage control file
using the #pragma calls directive if the information about which functions that might
be called is available when compiling.
When the function does not perform any calls, the list is empty:
possible calls MyFunc8: ;
Syntactic components
This section describes the syntactical components that can be used by the stack usage
control directives.
category
Syntax [ name ]
Description A call graph root category. You can use any name you like. Categories are not
case-sensitive.
func-spec
Syntax [ ? ] name [ module-spec ]
Description Specifies the name of a symbol, and for module-local symbols, the name of the module
it is defined in. Normally, if func-spec does not match a symbol in the program, a
warning is emitted. Prefixing with ? suppresses this warning.
409
AFE1_AFE2-1:1
Syntactic components
module-spec
Syntax [name [ (name) ]]
Description Specifies the name of a module, and optionally, in parentheses, the name of the library
it belongs to. To distinguish between modules with the same name, you can specify:
● The complete path of the file ("D:\C1\test\file.o")
● As many path elements as are needed at the end of the path ("test\file.o")
● Some path elements at the start of the path, followed by "...", followed by some
path elements at the end ("D:\...\file.o").
Note: When using multi-file compilation (--mfc), multiple files are compiled into a
single module, named after the first file.
[file.r43]
[file.r43(lib.a)]
["D:\C1\test\file.r43"]
name
Description A name can be either an identifier or a quoted string.
The first character of an identifier must be either a letter or one of the characters "_",
"$", or ".". The rest of the characters can also be digits.
A quoted string starts and ends with " and can contain any character. Two consecutive
" characters can be used inside a quoted string to represent a single ".
MyFun
file.r43
"file-1.r43"
call-info
Syntax calls func-spec [ , func-spec... ][ : stack-size ]
Description Specifies one or more called functions, and optionally, the stack size at the calls.
AFE1_AFE2-1:1
The stack usage control file
stack-size
Syntax [ stack ] size
([ stack ] size)
Description Specifies the size of a stack frame. A stack may not be specified more than once.
Example 24
stack 28
size
Description A decimal integer, or 0x followed by a hexadecimal integer. Either alternative can
optionally be followed by a suffix indicating a power of two (K=210, M=220, G=230,
T=240, P=250).
24
0x18
2048
2K
411
AFE1_AFE2-1:1
Syntactic components
AFE1_AFE2-1:1
Implementation-defined
behavior for Standard C
● Descriptions of implementation-defined behavior
The text in this chapter applies to the DLIB runtime environment. Because the
CLIB runtime environment does not follow Standard C, its
implementation-defined behavior is not documented. See also The CLIB runtime
environment, page 161.
J.3.1 TRANSLATION
where filename is the name of the source file in which the error was encountered,
linenumber is the line number at which the compiler detected the error, level is the
level of seriousness of the message (remark, warning, error, or fatal error), tag is a
unique tag that identifies the message, and message is an explanatory message, possibly
several lines.
413
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
J.3.2 ENVIRONMENT
Main (5.1.2.1)
The function called at program startup is called main. No prototype is declared for
main, and the only definition supported for main is:
int main(void)
To change this behavior for the DLIB runtime environment, see System initialization,
page 138.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.3 IDENTIFIERS
J.3.4 CHARACTERS
415
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.5 INTEGERS
417
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
ptrdiff_t (6.5.6)
For information about ptrdiff_t, see ptrdiff_t, page 310.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.8 HINTS
419
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
J.3.10 QUALIFIERS
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
baseaddr
building_runtime
can_instantiate
codeseg
cspy_support
define_type_info
do_not_instantiate
early_dynamic_initialization
function
function_effects
hdrstop
important_typedef
instantiate
keep_definition
library_default_requirements
library_provides
library_requirement_override
memory
module_name
no_pch
once
system_include
warnings
421
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
signal() (7.14.1.1)
The signal part of the library is not supported.
Note: The default implementation of signal does not perform anything. Use the
template source code to implement application-specific signal handling. See signal,
page 145 and raise, page 143, respectively.
423
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
remove() (7.19.4.1)
The effect of a remove operation on an open file depends on the application-specific
implementation of the low-level file routines. See Briefly about input and output (I/O),
page 116.
rename() (7.19.4.2)
The effect of renaming a file to an already existing filename depends on the
application-specific implementation of the low-level file routines. See Briefly about
input and output (I/O), page 116.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
425
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
clock() (7.23.2.1)
The application must supply an implementation of the clock function. See clock, page
140.
J.3.13 ARCHITECTURE
For information about sizes, ranges, etc for all basic types, see Data representation, page
303.
The limit macros for the exact-width, minimum-width, and fastest minimum-width
integer types defined in stdint.h have the same ranges as char, short, int, long,
and long long.
The floating-point constant FLT_ROUNDS has the value 1 (to nearest) and the
floating-point constant FLT_EVAL_METHOD has the value 0 (treat as is).
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.4 LOCALE
427
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
AFE1_AFE2-1:1
Implementation-defined
behavior for C89
● Descriptions of implementation-defined behavior
TRANSLATION
Diagnostics (5.1.1.3)
Diagnostics are produced in the form:
filename,linenumber level[tag]: message
where filename is the name of the source file in which the error was encountered,
linenumber is the line number at which the compiler detected the error, level is the
level of seriousness of the message (remark, warning, error, or fatal error), tag is a
unique tag that identifies the message, and message is an explanatory message, possibly
several lines.
ENVIRONMENT
int main(void)
To change this behavior for the DLIB runtime environment, see System initialization,
page 138. To change this behavior for the CLIB runtime environment, see Customizing
system initialization, page 166.
429
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
IDENTIFIERS
CHARACTERS
AFE1_AFE2-1:1
Implementation-defined behavior for C89
same representation value is used for each member in the character sets except for the
escape sequences listed in the ISO standard.
INTEGERS
431
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
FLOATING POINT
AFE1_AFE2-1:1
Implementation-defined behavior for C89
REGISTERS
433
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
QUALIFIERS
DECLARATORS
STATEMENTS
PREPROCESSING DIRECTIVES
AFE1_AFE2-1:1
Implementation-defined behavior for C89
file currently being processed. If there is no grandparent file and the file is not found,
the search continues as if the filename was enclosed in angle brackets.
baseaddr
building_runtime
can_instantiate
codeseg
cspy_support
define_type_info
do_not_instantiate
early_dynamic_initialization
function
function_effects
hdrstop
important_typedef
instantiate
keep_definition
library_default_requirements
library_provides
435
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
library_requirement_override
memory
module_name
no_pch
once
system_include
warnings
AFE1_AFE2-1:1
Implementation-defined behavior for C89
signal() (7.7.1.1)
The signal part of the library is not supported.
Note: The default implementation of signal does not perform anything. Use the
template source code to implement application-specific signal handling. See signal,
page 145 and raise, page 143, respectively.
Files (7.9.3)
Whether the file position indicator of an append-mode stream is initially positioned at
the beginning or the end of the file, depends on the application-specific implementation
of the low-level file routines.
Whether a write operation on a text stream causes the associated file to be truncated
beyond that point, depends on the application-specific implementation of the low-level
file routines. See Briefly about input and output (I/O), page 116.
The characteristics of the file buffering is that the implementation supports files that are
unbuffered, line buffered, or fully buffered.
Whether a zero-length file actually exists depends on the application-specific
implementation of the low-level file routines.
Rules for composing valid file names depends on the application-specific
implementation of the low-level file routines.
Whether the same file can be simultaneously open multiple times depends on the
application-specific implementation of the low-level file routines.
437
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
remove() (7.9.4.1)
The effect of a remove operation on an open file depends on the application-specific
implementation of the low-level file routines. See Briefly about input and output (I/O),
page 116.
rename() (7.9.4.2)
The effect of renaming a file to an already existing filename depends on the
application-specific implementation of the low-level file routines. See Briefly about
input and output (I/O), page 116.
%p in printf() (7.9.6.1)
The argument to a %p conversion specifier, print pointer, to printf() is treated as
having the type void *. The value will be printed as a hexadecimal number, similar to
using the %x conversion specifier.
%p in scanf() (7.9.6.2)
The %p conversion specifier, scan pointer, to scanf() reads a hexadecimal number and
converts it into a value with the type void *.
AFE1_AFE2-1:1
Implementation-defined behavior for C89
Environment (7.10.4.4)
The set of available environment names and the method for altering the environment list
is described in getenv, page 141.
system() (7.10.4.5)
How the command processor works depends on how you have implemented the system
function. See system, page 146.
clock() (7.12.2.1)
From where the system clock starts counting depends on how you have implemented the
clock function. See clock, page 140.
439
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
signal() (7.7.1.1)
The signal part of the library is not supported.
Files (7.9.3)
There are no other streams than stdin and stdout. This means that a file system is not
implemented.
AFE1_AFE2-1:1
Implementation-defined behavior for C89
remove() (7.9.4.1)
There are no other streams than stdin and stdout. This means that a file system is not
implemented.
rename() (7.9.4.2)
There are no other streams than stdin and stdout. This means that a file system is not
implemented.
%p in printf() (7.9.6.1)
The argument to a %p conversion specifier, print pointer, to printf() is treated as
having the type 'char *'. The value will be printed as a hexadecimal number, similar
to using the %x conversion specifier.
%p in scanf() (7.9.6.2)
The %p conversion specifier, scan pointer, to scanf() reads a hexadecimal number and
converts it into a value with the type 'void *'.
441
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
Environment (7.10.4.4)
Environments are not supported.
system() (7.10.4.5)
The system() function is not supported.
clock() (7.12.2.1)
The clock() function is not supported.
AFE1_AFE2-1:1
Index
Index
of incomplete types . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
A single-value initialization . . . . . . . . . . . . . . . . . . . . . . . 203
abort asm, __asm (language extension) . . . . . . . . . . . . . . . . . . . 172
implementation-defined behavior . . . . . . . . . . . . . . . . 425 assembler code
implementation-defined behavior in C89 (CLIB) . . . . 441 calling from C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
implementation-defined behavior in C89 (DLIB) . . . . 438 calling from C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
system termination (DLIB) . . . . . . . . . . . . . . . . . . . . . 137 inserting inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
absolute location assembler directives
data, placing at (@) . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 for call frame information . . . . . . . . . . . . . . . . . . . . . . 193
language support for . . . . . . . . . . . . . . . . . . . . . . . . . . 200 using in inline assembler code . . . . . . . . . . . . . . . . . . . 171
#pragma location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 assembler instructions, inserting inline . . . . . . . . . . . . . . . 171
ADC12 module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 assembler labels
addressing. See memory types, data models, default for application startup . . . . . . . . . . . . . . . . . . . . 54
and code models making public (--public_equ) . . . . . . . . . . . . . . . . . . . . 294
algorithm (STL header file) . . . . . . . . . . . . . . . . . . . . . . . 382 assembler language interface . . . . . . . . . . . . . . . . . . . . . . 169
alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 calling convention. See assembler code
forcing stricter (#pragma data_alignment) . . . . . . . . . . 336 assembler list file, generating . . . . . . . . . . . . . . . . . . . . . . 282
in structures (#pragma pack) . . . . . . . . . . . . . . . . . . . . 347 assembler output file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
in structures, causing problems . . . . . . . . . . . . . . . . . . 234 asserts
of an object (__ALIGNOF__) . . . . . . . . . . . . . . . . . . . 200 implementation-defined behavior of . . . . . . . . . . . . . . 422
of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 implementation-defined behavior of in C89, (CLIB) . . 440
alignment (pragma directive) . . . . . . . . . . . . . . . . . . 421, 435 implementation-defined behavior of in C89, (DLIB) . . 436
__ALIGNOF__ (operator) . . . . . . . . . . . . . . . . . . . . . . . . 200 including in application . . . . . . . . . . . . . . . . . . . . . . . . 375
anonymous structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 assert.h (CLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 386
anonymous symbols, creating . . . . . . . . . . . . . . . . . . . . . . 197 assert.h (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 380
ANSI C. See C89 __assignment_by_bitwise_copy_allowed, symbol used
application in library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
building, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 @ (operator)
execution, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . 50 placing at absolute address . . . . . . . . . . . . . . . . . . . . . . 237
startup and termination (CLIB) . . . . . . . . . . . . . . . . . . 165 placing in segments . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
startup and termination (DLIB) . . . . . . . . . . . . . . . . . . 135 atomic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
argv (argument), implementation-defined behavior . . . . . 414 __monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
arrays attributes
designated initializers in . . . . . . . . . . . . . . . . . . . . . . . 197 object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
global, accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
implementation-defined behavior . . . . . . . . . . . . . . . . 418 auto variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
implementation-defined behavior in C89 . . . . . . . . . . . 433 at function entrance . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
incomplete at end of structs . . . . . . . . . . . . . . . . . . . . . 197 programming hints for efficient code . . . . . . . . . . . . . . 246
non-lvalue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 using in inline assembler statements . . . . . . . . . . . . . . 171
443
AFE1_AFE2-1:1
building_runtime (pragma directive). . . . . . . . . . . . . 421, 435
B __BUILD_NUMBER__ (predefined symbol) . . . . . . . . . 370
backtrace information See call frame information
Barr, Michael . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
baseaddr (pragma directive) . . . . . . . . . . . . . . . . . . . 421, 435
C
__BASE_FILE__ (predefined symbol) . . . . . . . . . . . . . . . 370 C and C++ linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
basic type names, using in preprocessor expressions C/C++ calling convention. See calling convention
(--migration_preprocessor_extensions) . . . . . . . . . . . . . . . 284 C header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
basic_template_matching (pragma directive) . . . . . . . . . . 333 C language, overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 call frame information . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
batch files in assembler list file . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
error return codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 in assembler list file (-lA) . . . . . . . . . . . . . . . . . . . . . . 282
none for building library from command line . . . . . . . 125 call frame information, disabling (--no_call_frame_info) . 286
__bcd_add_long (intrinsic function) . . . . . . . . . . . . . . . . . 357 call graph root (stack usage control directive) . . . . . . . . . . 405
__bcd_add_long_long (intrinsic function) . . . . . . . . . . . . 357 call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
__bcd_add_short (intrinsic function) . . . . . . . . . . . . . . . . 357 callee-save registers, stored on stack . . . . . . . . . . . . . . . . . . 68
__bic_SR_register (intrinsic function) . . . . . . . . . . . . . . . 357 calling convention
__bic_SR_register_on_exit (intrinsic function) . . . . . . . . 358 C++, requiring C linkage . . . . . . . . . . . . . . . . . . . . . . . 180
binary streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 in compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
binary streams in C89 (CLIB) . . . . . . . . . . . . . . . . . . . . . . 440 overriding default (__cc_rom) . . . . . . . . . . . . . . . . . . . 321
binary streams in C89 (DLIB). . . . . . . . . . . . . . . . . . . . . . 437 overriding default (__cc_version1) . . . . . . . . . . . . . . . 322
__bis_GIE_interrupt_state (intrinsic function) . . . . . . . . . 358 overriding default (__cc_version2) . . . . . . . . . . . . . . . 322
bis_nmi_ie1 (pragma directive) . . . . . . . . . . . . . . . . . . . . 334 calloc (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
__bis_SR_register (intrinsic function) . . . . . . . . . . . . . . . 358 See also heap
__bis_SR_register_on_exit (intrinsic function). . . . . . . . . 358 implementation-defined behavior in C89 (CLIB) . . . . 441
bit negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 implementation-defined behavior in C89 (DLIB) . . . . 438
bitfields calls (pragma directive). . . . . . . . . . . . . . . . . . . . . . . . . . . 335
data representation of . . . . . . . . . . . . . . . . . . . . . . . . . . 306 call_graph_root (pragma directive) . . . . . . . . . . . . . . . . . . 335
hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 call-info (in stack usage control file). . . . . . . . . . . . . . . . . 410
implementation-defined behavior . . . . . . . . . . . . . . . . 419 can_instantiate (pragma directive) . . . . . . . . . . . . . . 421, 435
implementation-defined behavior in C89 . . . . . . . . . . . 433 cassert (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 382
non-standard types in . . . . . . . . . . . . . . . . . . . . . . . . . . 200 cast operators
bitfields (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . 334 in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . 206, 217
bits in a byte, implementation-defined behavior . . . . . . . . 415 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . 206
bold style, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 casting
bool (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 between pointer types . . . . . . . . . . . . . . . . . . . . . . . . . . 63
adding support for in CLIB . . . . . . . . . . . . . . . . . . . . . 386 of pointers and integers . . . . . . . . . . . . . . . . . . . . . . . . 310
adding support for in DLIB . . . . . . . . . . . . . . . . . 380, 383 pointers to integers, language extension . . . . . . . . . . . . 202
BSLSIGNATURE (segment) . . . . . . . . . . . . . . . . . . . . . . 389 category (in stack usage control file) . . . . . . . . . . . . . . . . 409
AFE1_AFE2-1:1
Index
445
AFE1_AFE2-1:1
common subexpr elimination (compiler transformation) . 243 for locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
disabling (--no_cse) . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 for printf and scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
compilation date for strtod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
exact time of (__TIME__) . . . . . . . . . . . . . . . . . . . . . . 374 in library configuration files. . . . . . . . . . . . . . . . . . . . . 125
identifying (__DATE__) . . . . . . . . . . . . . . . . . . . . . . . 371 consistency, module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
compiler const
environment variables . . . . . . . . . . . . . . . . . . . . . . . . . 256 declaring objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
invocation syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 non-top level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
output from . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 constants, placing in named segment . . . . . . . . . . . . . . . . 336
compiler listing, generating (-l). . . . . . . . . . . . . . . . . . . . . 282 __constrange(), symbol used in library . . . . . . . . . . . . . . . 385
compiler object file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 __construction_by_bitwise_copy_allowed, symbol used
including debug information in (--debug, -r) . . . . . . . . 272 in library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
output from compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 258 constseg (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . 336
compiler optimization levels . . . . . . . . . . . . . . . . . . . . . . . 242 const_cast (cast operator) . . . . . . . . . . . . . . . . . . . . . . . . . 206
compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 contents, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
passing to compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 control characters,
reading from file (-f) . . . . . . . . . . . . . . . . . . . . . . . . . . 280 implementation-defined behavior . . . . . . . . . . . . . . . . . . . 427
specifying parameters . . . . . . . . . . . . . . . . . . . . . . . . . 265 conventions, used in this guide . . . . . . . . . . . . . . . . . . . . . . 33
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 copy initialization, of segments. . . . . . . . . . . . . . . . . . . . . 108
syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
for creating skeleton code . . . . . . . . . . . . . . . . . . . . . . 179 __CORE__ (predefined symbol). . . . . . . . . . . . . . . . . . . . 370
--warnings_affect_exit_code . . . . . . . . . . . . . . . . . . . . 259 core, identifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
compiler platform, identifying . . . . . . . . . . . . . . . . . . . . . 372 cos (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
compiler subversion number . . . . . . . . . . . . . . . . . . . . . . . 374 cos (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 133–134
compiler transformations . . . . . . . . . . . . . . . . . . . . . . . . . 240 cosf (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 133–134
compiler version number . . . . . . . . . . . . . . . . . . . . . . . . . 374 cosl (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 133–134
compiling __COUNTER__ (predefined symbol). . . . . . . . . . . . . . . . 370
from the command line . . . . . . . . . . . . . . . . . . . . . . . . . 54 __cplusplus (predefined symbol) . . . . . . . . . . . . . . . . . . . 370
syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 csetjmp (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 383
complex numbers, supported in Embedded C++ . . . . . . . . 206 csignal (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 383
complex (library header file). . . . . . . . . . . . . . . . . . . . . . . 381 cspy_support (pragma directive) . . . . . . . . . . . . . . . . 421, 435
complex.h (library header file) . . . . . . . . . . . . . . . . . . . . . 380 CSTACK (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
compound literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 See also stack
computer style, typographic convention . . . . . . . . . . . . . . . 34 CSTART (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
configuration cstartup (system startup code)
basic project settings . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 customizing system initialization . . . . . . . . . . . . . . . . . 138
__low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 source files for (CLIB) . . . . . . . . . . . . . . . . . . . . . . . . . 165
configuration symbols source files for (DLIB). . . . . . . . . . . . . . . . . . . . . . . . . 135
for file input and output . . . . . . . . . . . . . . . . . . . . . . . . 149 cstat_disable (pragma directive) . . . . . . . . . . . . . . . . . . . . 331
cstat_enable (pragma directive) . . . . . . . . . . . . . . . . . . . . 331
AFE1_AFE2-1:1
Index
447
AFE1_AFE2-1:1
DATA16_ID (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 393 delete (keyword) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
DATA16_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 --dependencies (compiler option) . . . . . . . . . . . . . . . . . . . 273
DATA16_P (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 deque (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 382
__data16_read_addr (intrinsic function) . . . . . . . . . . . . . . 359 destructors and interrupts, using . . . . . . . . . . . . . . . . . . . . 212
__data16_size_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 device description files, preconfigured for C-SPY . . . . . . . 42
DATA16_Z (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 diagnostic messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
__data20 (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 323 classifying as compilation errors . . . . . . . . . . . . . . . . . 274
DATA20_AC (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 395 classifying as compilation remarks . . . . . . . . . . . . . . . 274
DATA20_AN (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 395 classifying as compiler warnings . . . . . . . . . . . . . . . . . 275
DATA20_C (segment) . . . . . . . . . . . . . . . . . . . . . . . 395–396 disabling compiler warnings . . . . . . . . . . . . . . . . . . . . 290
DATA20_HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . 396 disabling wrapping of in compiler . . . . . . . . . . . . . . . . 290
DATA20_I (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 enabling compiler remarks . . . . . . . . . . . . . . . . . . . . . . 296
DATA20_ID (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 396 listing all used by compiler . . . . . . . . . . . . . . . . . . . . . 275
__data20_longjmp (intrinsic function) . . . . . . . . . . . . . . . 360 suppressing in compiler . . . . . . . . . . . . . . . . . . . . . . . . 275
DATA20_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 --diagnostics_tables (compiler option) . . . . . . . . . . . . . . . 275
DATA20_P (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 diagnostics, implementation-defined behavior . . . . . . . . . 413
__data20_read_char (intrinsic function) . . . . . . . . . . . . . . 360 diag_default (pragma directive) . . . . . . . . . . . . . . . . . . . . 339
__data20_read_long (intrinsic function) . . . . . . . . . . . . . . 360 --diag_error (compiler option) . . . . . . . . . . . . . . . . . . . . . 274
__data20_read_short (intrinsic function) . . . . . . . . . . . . . 360 diag_error (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 340
__data20_setjmp (intrinsic function). . . . . . . . . . . . . . . . . 360 --diag_remark (compiler option) . . . . . . . . . . . . . . . . . . . . 274
__data20_write_char (intrinsic function) . . . . . . . . . . . . . 361 diag_remark (pragma directive) . . . . . . . . . . . . . . . . . . . . 340
__data20_write_long (intrinsic function) . . . . . . . . . . . . . 361 --diag_suppress (compiler option) . . . . . . . . . . . . . . . . . . 275
__data20_write_short (intrinsic function) . . . . . . . . . . . . . 361 diag_suppress (pragma directive) . . . . . . . . . . . . . . . . . . . 340
DATA20_Z (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 --diag_warning (compiler option) . . . . . . . . . . . . . . . . . . . 275
__DATE__ (predefined symbol). . . . . . . . . . . . . . . . . . . . 371 diag_warning (pragma directive) . . . . . . . . . . . . . . . . . . . 341
date (library function), configuring support for . . . . . . . . . 123 DIFUNCT (segment) . . . . . . . . . . . . . . . . . . . . . . . . 108, 398
--debug (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 272 directives, pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43, 331
debug information, including in object file . . . . . . . . . . . . 272 directory, specifying as parameter . . . . . . . . . . . . . . . . . . 264
decimal point, implementation-defined behavior . . . . . . . 427 __disable_interrupt (intrinsic function) . . . . . . . . . . . . . . . 361
declarations --discard_unused_publics (compiler option) . . . . . . . . . . . 276
empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
in for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 DLIB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Kernighan & Ritchie . . . . . . . . . . . . . . . . . . . . . . . . . . 247 configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 configuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124, 277
declarations and statements, mixing . . . . . . . . . . . . . . . . . 197 naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
declarators, implementation-defined behavior in C89 . . . . 434 reference information. See the online help system . . . . 377
define_type_info (pragma directive) . . . . . . . . . . . . . 421, 435 runtime environment . . . . . . . . . . . . . . . . . . . . . . . . . . 115
__delay_cycles (intrinsic function) . . . . . . . . . . . . . . . . . . 361 --dlib (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . 276
delete operator (extended EC++) . . . . . . . . . . . . . . . . . . . 211 --dlib_config (compiler option). . . . . . . . . . . . . . . . . . . . . 277
AFE1_AFE2-1:1
Index
449
AFE1_AFE2-1:1
_exit (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 file dependencies, tracking . . . . . . . . . . . . . . . . . . . . . . . . 273
__exit (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 137 file input and output, configuration symbols for . . . . . . . . 149
exp (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 file paths, specifying for #include files . . . . . . . . . . . . . . . 282
expf (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 file position, implementation-defined behavior . . . . . . . . . 423
expl (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 file streams lock interface . . . . . . . . . . . . . . . . . . . . . . . . . 156
export keyword, missing from Extended EC++ . . . . . . . . 213 file systems in C89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
extended command line file file (zero-length), implementation-defined behavior . . . . . 424
for compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 filename
passing options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 extension for device description files . . . . . . . . . . . . . . . 42
Extended Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . 206 extension for header files . . . . . . . . . . . . . . . . . . . . . . . . 41
enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 of object file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
extended keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 search procedure for. . . . . . . . . . . . . . . . . . . . . . . . . . . 256
enabling (-e) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 specifying as parameter . . . . . . . . . . . . . . . . . . . . . . . . 264
overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 filenames (legal), implementation-defined behavior . . . . . 424
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 fileno, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
syntax files, implementation-defined behavior
object attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 handling of temporary . . . . . . . . . . . . . . . . . . . . . . . . . 424
type attributes on data objects . . . . . . . . . . . . . . 62, 318 multibyte characters in . . . . . . . . . . . . . . . . . . . . . . . . . 424
type attributes on functions . . . . . . . . . . . . . . . . . . . 319 opening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
__ramfunc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 float (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
extern "C" linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 floating-point constants
hexadecimal notation . . . . . . . . . . . . . . . . . . . . . . . . . . 197
F hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
floating-point environment, accessing or not . . . . . . . . . . 352
-f (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 floating-point expressions
far (memory type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 contracting or not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
fatal error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 using in preprocessor extensions . . . . . . . . . . . . . . . . . 284
fdopen, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 floating-point format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
fegettrapdisable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
fegettrapenable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 implementation-defined behavior . . . . . . . . . . . . . . . . 417
FENV_ACCESS, implementation-defined behavior . . . . 418 implementation-defined behavior in C89 . . . . . . . . . . . 432
fenv.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 380 special cases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
additional C functionality. . . . . . . . . . . . . . . . . . . . . . . 383 32-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
fgetpos (library function) 64-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
implementation-defined behavior in C89 . . . . . . . . . . . 438 floating-point numbers, support for in printf formatters . . 163
implementation-defined behavior. . . . . . . . . . . . . . . . . 425 floating-point status flags . . . . . . . . . . . . . . . . . . . . . . . . . 383
field width, library support for . . . . . . . . . . . . . . . . . . . . . 164 floating-point type, configuring size of double . . . . . . . . . . 57
__FILE__ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 371 float.h (library header file) . . . . . . . . . . . . . . . . . . . . 380, 386
file buffering, implementation-defined behavior . . . . . . . . 423 FLT_EVAL_METHOD, implementation-defined
behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417, 422, 426
AFE1_AFE2-1:1
Index
451
AFE1_AFE2-1:1
--guard_calls (compiler option). . . . . . . . . . . . . . . . . . . . . 280 HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
guidelines, reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 heap (zero-sized), implementation-defined behavior . . . . 425
hints
AFE1_AFE2-1:1
Index
453
AFE1_AFE2-1:1
intptr_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 iostream (library header file). . . . . . . . . . . . . . . . . . . . . . . 381
ptrdiff_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 IPE (Intellectual Property Encapsulation) . . . . . . . . . . . . . 153
size_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 IPECODE16 (segment). . . . . . . . . . . . . . . . . . . . . . . . . . . 400
uintptr_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 IPEDATA16_C (segment) . . . . . . . . . . . . . . . . . . . . . . . . 401
integral promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 IPEDATA16_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . 401
Intellectual Property Encapsulation (IPE) . . . . . . . . . . . . . 153 IPESIGNATURE (segment) . . . . . . . . . . . . . . . . . . . . . . . 401
internal error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 IPE_B1 (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
__interrupt (extended keyword) . . . . . . . . . . . . . . . . . 74, 323 IPE_B2 (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 354 iso646.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 380
interrupt functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 ISR_CODE (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
for MSP430X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . . . 107 istream (library header file). . . . . . . . . . . . . . . . . . . . . . . . 381
interrupt handler. See interrupt service routine italic style, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
interrupt service routine . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 iterator (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 382
interrupt state, restoring . . . . . . . . . . . . . . . . . . . . . . . . . . 366 I/O register. See SFR
interrupt vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 I/O, character-based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
specifying with pragma directive . . . . . . . . . . . . . . . . . 354 I2C (I2CIV) module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Interrupt Vector Generators, writing interrupt service
routines for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
interrupt vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 J
in linker configuration file . . . . . . . . . . . . . . . . . . . . . . 107 JTAGSIGNATURE (segment) . . . . . . . . . . . . . . . . . . . . . 402
INTVEC segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
interrupts
disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
during function execution . . . . . . . . . . . . . . . . . . . . . 76
K
keep_definition (pragma directive) . . . . . . . . . . . . . . 421, 435
processor state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Kernighan & Ritchie function declarations . . . . . . . . . . . . 247
using with C++ destructors . . . . . . . . . . . . . . . . . . . . . 212
disallowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
intptr_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
__intrinsic (extended keyword). . . . . . . . . . . . . . . . . . . . . 324
extended, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . 42
intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
intrinsics.h (header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 355
L
-l (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
inttypes.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 380
for creating skeleton code . . . . . . . . . . . . . . . . . . . . . . 179
INTVEC (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 107, 399
labels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
intwri.c (library source code) . . . . . . . . . . . . . . . . . . . . . . 164
assembler, making public . . . . . . . . . . . . . . . . . . . . . . . 294
invocation syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
__iar_program_start . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
iomanip (library header file) . . . . . . . . . . . . . . . . . . . . . . . 381
__program_start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
ios (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Labrosse, Jean J. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
iosfwd (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 381
AFE1_AFE2-1:1
Index
455
AFE1_AFE2-1:1
log10l (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 implementation-defined behavior in C89 . . . . . . . 438, 441
long double (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Mann, Bernhard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
long float (data type), synonym for double . . . . . . . . . . . . 202 map (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
long long (data type) map, linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
avoiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 math functions rounding mode,
restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 implementation-defined behavior . . . . . . . . . . . . . . . . . . . 426
long long (data type), signed and unsigned . . . . . . . . . . . . 304 math functions (library functions) . . . . . . . . . . . . . . . . . . . 131
long (data type), signed and unsigned . . . . . . . . . . . . . . . . 304 MathLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
longjmp, restrictions for using . . . . . . . . . . . . . . . . . . . . . 379 math.h (library header file) . . . . . . . . . . . . . . . . . . . . 380, 386
loop unrolling (compiler transformation) . . . . . . . . . . . . . 244 max recursion depth (stack usage control directive) . . . . . 407
disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 MB_LEN_MAX, implementation-defined behavior . . . . . 426
#pragma unroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Medium (data model) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
loop-invariant expressions . . . . . . . . . . . . . . . . . . . . . . . . 244 _medium_write (library function) . . . . . . . . . . . . . . . . . . . 163
__low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 memory
customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56, 60, 191
initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 using data16 method . . . . . . . . . . . . . . . . . . . . . . . . 192
low_level_init.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135, 165 using data20 method . . . . . . . . . . . . . . . . . . . . . . . . 192
__low_power_mode_n (intrinsic function) . . . . . . . . . . . . 364 allocating in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
__low_power_mode_off_on_exit (intrinsic function) . . . . 364 dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
low-level processor operations . . . . . . . . . . . . . . . . . . . . . 198 heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
RAM, saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
releasing in C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
M stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
macros saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
embedded in #pragma optimize . . . . . . . . . . . . . . . . . . 346 used by global or static variables . . . . . . . . . . . . . . . . . . 60
ERANGE (in errno.h) . . . . . . . . . . . . . . . . . . . . . 422, 436 memory clobber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
inclusion of assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 memory consumption, reducing . . . . . . . . . . . . . . . . . . . . 163
NULL, implementation-defined behavior . . . . . . . . . . 423 memory management, type-safe . . . . . . . . . . . . . . . . . . . . 205
in C89 for CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 memory map
in C89 for DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 initializing SFRs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
substituted in #pragma directives . . . . . . . . . . . . . . . . . 198 linker configuration for . . . . . . . . . . . . . . . . . . . . . . . . 101
variadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 memory placement
--macro_positions_in_diagnostics (compiler option) . . . . 284 of linker segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
main (function) using type definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
definition (C89) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 Memory Protection Unit (MPU) . . . . . . . . . . . . . . . . . . . . 152
implementation-defined behavior . . . . . . . . . . . . . . . . 414 memory segment. See segment
malloc (library function) memory types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
See also heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
placing variables in . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
AFE1_AFE2-1:1
Index
457
AFE1_AFE2-1:1
__noreturn (extended keyword) . . . . . . . . . . . . . . . . . . . . 327
Normal DLIB (library configuration) . . . . . . . . . . . . . . . . 127 O
Not a number (NaN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 -O (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
__no_alloc (extended keyword) . . . . . . . . . . . . . . . . . . . . 324 -o (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
__no_alloc_str (operator) . . . . . . . . . . . . . . . . . . . . . . . . . 325 object attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
__no_alloc_str16 (operator) . . . . . . . . . . . . . . . . . . . . . . . 325 object filename, specifying (-o) . . . . . . . . . . . . . . . . . . . . 292
__no_alloc16 (extended keyword) . . . . . . . . . . . . . . . . . . 324 object module name, specifying (--module_name) . . . . . . 285
--no_call_frame_info (compiler option) . . . . . . . . . . . . . . 286 object_attribute (pragma directive) . . . . . . . . . . . . . . 251, 345
--no_code_motion (compiler option) . . . . . . . . . . . . . . . . 286 offsetof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
no_crosscall (#pragma optimize parameter) . . . . . . . . . . . 346 --omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 291
no_crossjump (#pragma optimize parameter) . . . . . . . . . . 346 once (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 421, 436
--no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 286 --only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 292
no_epilogue (pragma directive) . . . . . . . . . . . . . . . . . . . . 345 operators
__no_init (extended keyword) . . . . . . . . . . . . . . . . . 251, 326 See also @ (operator)
--no_inline (compiler option) . . . . . . . . . . . . . . . . . . . . . . 287 for cast
__no_multiplier (extended keyword) . . . . . . . . . . . . . . . . 326 in Extended EC++. . . . . . . . . . . . . . . . . . . . . . . . . . 206
__no_operation (intrinsic function) . . . . . . . . . . . . . . . . . . 364 missing from Embedded C++ . . . . . . . . . . . . . . . . . 206
--no_path_in_file_macros (compiler option). . . . . . . . . . . 287 for segment control . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
no_pch (pragma directive) . . . . . . . . . . . . . . . . . . . . 421, 436 new and delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
__no_pic (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 326 precision for 32-bit float . . . . . . . . . . . . . . . . . . . . . . . 308
--no_rw_dynamic_init (compiler option) . . . . . . . . . . . . . 287 precision for 64-bit float . . . . . . . . . . . . . . . . . . . . . . . 308
--no_size_constraints (compiler option) . . . . . . . . . . . . . . 288 sizeof, implementation-defined behavior . . . . . . . . . . . 427
--no_static_destruction (compiler option) . . . . . . . . . . . . . 288 variants for cast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
--no_system_include (compiler option) . . . . . . . . . . . . . . 288 _Pragma (preprocessor) . . . . . . . . . . . . . . . . . . . . . . . . 197
--no_tbaa (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 289 __ALIGNOF__, for alignment control. . . . . . . . . . . . . 200
--no_typedefs_in_diagnostics (compiler option) . . . . . . . . 289 __memory_of. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
--no_ubrof_messages (compiler option) . . . . . . . . . . . . . . 290 ?, language extensions for . . . . . . . . . . . . . . . . . . . . . . 219
--no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 290 optimization
--no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 290 code motion, disabling . . . . . . . . . . . . . . . . . . . . . . . . . 286
--no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 290 common sub-expression elimination, disabling . . . . . . 286
NULL configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
implementation-defined behavior . . . . . . . . . . . . . . . . 423 disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
implementation-defined behavior in C89 (CLIB) . . . . 439 function inlining, disabling (--no_inline) . . . . . . . . . . . 287
implementation-defined behavior in C89 (DLIB) . . . . 436 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
in library header file (CLIB) . . . . . . . . . . . . . . . . . . . . 386 loop unrolling, disabling . . . . . . . . . . . . . . . . . . . . . . . 290
pointer constant, relaxation to Standard C . . . . . . . . . . 202 specifying (-O) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
numeric conversion functions, implementation-defined techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 type-based alias analysis, disabling (--tbaa) . . . . . . . . . 289
numeric (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 382 using pragma directive . . . . . . . . . . . . . . . . . . . . . . . . . 346
AFE1_AFE2-1:1
Index
459
AFE1_AFE2-1:1
#pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 putw, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
preprocessor extensions
compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
__VA_ARGS__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Q
#warning message . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 -Q (linker option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
preprocessor symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 qualifiers
defining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 const and volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
preserved registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 implementation-defined behavior . . . . . . . . . . . . . . . . 420
__PRETTY_FUNCTION__ (predefined symbol). . . . . . . 373 implementation-defined behavior in C89 . . . . . . . . . . . 434
primitives, for special functions . . . . . . . . . . . . . . . . . . . . . 73 queue (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 382
print formatter, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . 130
printf (library function) . . . . . . . . . . . . . . . . . . . . . . . 129, 163
choosing formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
configuration symbols . . . . . . . . . . . . . . . . . . . . . . . . . 148
R
-r (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 RAM
implementation-defined behavior . . . . . . . . . . . . . . . . 425 function execution in . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
implementation-defined behavior in C89 . . . . . . . 438, 441 initializers copied from ROM . . . . . . . . . . . . . . . . . . . . 52
selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 saving memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
__printf_args (pragma directive). . . . . . . . . . . . . . . . . . . . 348 __ramfunc (extended keyword) . . . . . . . . . . . . . . . . . . . . 327
printing characters, implementation-defined behavior . . . 427 cannot be used with ROPI . . . . . . . . . . . . . . . . . . . . . . . 80
processor configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 range errors, in linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
processor operations __raw (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 328
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
low-level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 read formatter, selecting . . . . . . . . . . . . . . . . . . . . . . 131, 165
program entry label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 reading guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
program termination, implementation-defined behavior . . 414 reading, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
programming hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 realloc (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
__program_start (label) . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 implementation-defined behavior in C89 . . . . . . . 438, 441
projects See also heap
basic settings for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 recursive functions
setting up for a library . . . . . . . . . . . . . . . . . . . . . . . . . 125 avoiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
prototypes, enforcing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 storing data on stack . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
ptrdiff_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . 310, 386 --reduce_stack_usage (compiler option) . . . . . . . . . . . . . . 294
PUBLIC (assembler directive) . . . . . . . . . . . . . . . . . . . . . 294 reentrancy (DLIB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
publication date, of this guide . . . . . . . . . . . . . . . . . . . . . . . . 2 reference information, typographic convention . . . . . . . . . . 34
--public_equ (compiler option) . . . . . . . . . . . . . . . . . . . . . 294 register keyword, implementation-defined behavior . . . . . 419
public_equ (pragma directive) . . . . . . . . . . . . . . . . . . . . . 348 register parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 185–186
putchar (library function) . . . . . . . . . . . . . . . . . . . . . . . . . 163 registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
putenv (library function), absent from DLIB . . . . . . . . . . 141
AFE1_AFE2-1:1
Index
461
AFE1_AFE2-1:1
runtime model definitions . . . . . . . . . . . . . . . . . . . . . . . . . 349 placing in sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
runtime type information, missing from Embedded C++ . 206 specifying (--segment) . . . . . . . . . . . . . . . . . . . . . . . . . 297
R4. See registers summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
R5. See registers too long for address range . . . . . . . . . . . . . . . . . . . . . . 110
too long, in linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
AFE1_AFE2-1:1
Index
463
AFE1_AFE2-1:1
implementation-defined behavior in C89 (CLIB) . . . . 440 anonymous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200, 235
implementation-defined behavior in C89 (DLIB) . . . . 437 implementation-defined behavior . . . . . . . . . . . . . . . . 419
stdint.h (library header file) . . . . . . . . . . . . . . . . . . . 380, 383 implementation-defined behavior in C89 . . . . . . . . . . . 433
stdio.h (library header file) . . . . . . . . . . . . . . . . . . . . 380, 386 packing and unpacking . . . . . . . . . . . . . . . . . . . . . . . . 235
stdio.h, additional C functionality . . . . . . . . . . . . . . . . . . . 384 placing in memory type . . . . . . . . . . . . . . . . . . . . . . . . . 64
stdlib.h (library header file) . . . . . . . . . . . . . . . . . . . 380, 386 subnormal numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122, 292 support, technical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
implementation-defined behavior . . . . . . . . . . . . . . . . 423 Sutter, Herb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
implementation-defined behavior in C89 (CLIB) . . . . 440 __swap_bytes (intrinsic function) . . . . . . . . . . . . . . . . . . . 367
implementation-defined behavior in C89 (DLIB) . . . . 437 switch statements, hints for using . . . . . . . . . . . . . . . . . . . 252
Steele, Guy L. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 SWPB (assembler instruction) . . . . . . . . . . . . . . . . . . . . . 367
STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 symbol names, using in preprocessor extensions . . . . . . . 285
strcasecmp, in string.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 symbols
strdup, in string.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 anonymous, creating . . . . . . . . . . . . . . . . . . . . . . . . . . 197
streambuf (library header file) . . . . . . . . . . . . . . . . . . . . . 381 including in output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
streams listing in linker map file . . . . . . . . . . . . . . . . . . . . . . . . 111
implementation-defined behavior . . . . . . . . . . . . . . . . 414 overview of predefined . . . . . . . . . . . . . . . . . . . . . . . . . 43
supported in Embedded C++ . . . . . . . . . . . . . . . . . . . . 206 preprocessor, defining . . . . . . . . . . . . . . . . . . . . . . . . . 271
strerror (library function) syntax
implementation-defined behavior in C89 (CLIB) . . . . . . . 442 command line options . . . . . . . . . . . . . . . . . . . . . . . . . 263
strerror (library function), implementation-defined extended keywords . . . . . . . . . . . . . . . . . . . . 62, 318–320
behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 invoking compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
strerror (library function), implementation-defined system function, implementation-defined behavior. . 415, 425
behavior in C89 (DLIB) . . . . . . . . . . . . . . . . . . . . . . . . . . 439 system locks interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
--strict (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 299 system startup
string (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 381 CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
strings, supported in Embedded C++ . . . . . . . . . . . . . . . . 206 customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
string.h (library header file) . . . . . . . . . . . . . . . . . . . 380, 386 DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
string.h, additional C functionality . . . . . . . . . . . . . . . . . . 384 initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
strncasecmp, in string.h. . . . . . . . . . . . . . . . . . . . . . . . . . . 384 system termination
strnlen, in string.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
strstream (library header file) . . . . . . . . . . . . . . . . . . . . . . 381 C-SPY interface to . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
strtod (library function), configuring support for . . . . . . . 151 DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
structure types system (library function)
alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 implementation-defined behavior in C89 . . . . . . . . . . . 442
layout of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 implementation-defined behavior in C89 (DLIB) . . . . 439
packed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 system_include (pragma directive) . . . . . . . . . . . . . . 421, 436
structures --system_include_dir (compiler option) . . . . . . . . . . . . . . 299
accessing using a pointer . . . . . . . . . . . . . . . . . . . . . . . 191
aligning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
AFE1_AFE2-1:1
Index
465
AFE1_AFE2-1:1
unions version
anonymous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200, 235 compiler subversion number . . . . . . . . . . . . . . . . . . . . 374
implementation-defined behavior . . . . . . . . . . . . . . . . 419 identifying C standard in use (__STDC_VERSION__) 374
implementation-defined behavior in C89 . . . . . . . . . . . 433 of compiler (__VER__) . . . . . . . . . . . . . . . . . . . . . . . . 374
universal character names, implementation-defined of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 version1 calling convention . . . . . . . . . . . . . . . . . . . . . . . 182
unroll (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . . 353 version2 calling convention . . . . . . . . . . . . . . . . . . . . . . . 182
unsigned char (data type) . . . . . . . . . . . . . . . . . . . . . 304–305 --version (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 300
changing to signed char . . . . . . . . . . . . . . . . . . . . . . . . 270 --vla (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
unsigned int (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 void, pointers to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
unsigned long long (data type) . . . . . . . . . . . . . . . . . . . . . 304 volatile
unsigned long (data type) . . . . . . . . . . . . . . . . . . . . . . . . . 304 and const, declaring objects . . . . . . . . . . . . . . . . . . . . . 314
unsigned short (data type) . . . . . . . . . . . . . . . . . . . . . . . . . 304 declaring objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
--use_c++_inline (compiler option) . . . . . . . . . . . . . . . . . 300 protecting simultaneously accesses variables . . . . . . . . 248
utility (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 382 rules for access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
V W
variable type information, omitting in object output . . . . . 291 #warning message (preprocessor extension) . . . . . . . . . . . 375
variables warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 classifying in compiler . . . . . . . . . . . . . . . . . . . . . . . . . 275
defined inside a function . . . . . . . . . . . . . . . . . . . . . . . . 68 disabling in compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 290
global exit code in compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 301
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 warnings icon, in this guide . . . . . . . . . . . . . . . . . . . . . . . . 35
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . 60 warnings (pragma directive) . . . . . . . . . . . . . . . . . . . 421, 436
hints for choosing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 --warnings_affect_exit_code (compiler option) . . . . 259, 301
local. See auto variables --warnings_are_errors (compiler option) . . . . . . . . . . . . . 301
non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 --warn_about_c_style_casts (compiler option) . . . . . . . . . 301
omitting type info . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 wchar_t (data type), adding support for in C . . . . . . . . . . . 305
placing at absolute addresses . . . . . . . . . . . . . . . . . . . . 239 wchar.h (library header file) . . . . . . . . . . . . . . . . . . . 380, 383
placing in named segments . . . . . . . . . . . . . . . . . . . . . 239 wctype.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 381
static weak (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 354
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . 60 web sites, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
taking the address of . . . . . . . . . . . . . . . . . . . . . . . . 246 white-space characters, implementation-defined behavior 414
variadic macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 write formatter, selecting . . . . . . . . . . . . . . . . . . . . . 164–165
vector (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 74, 354 __write_array, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . 384
cannot be used with ROPI . . . . . . . . . . . . . . . . . . . . . . . 80 __write_buffered (DLIB library function) . . . . . . . . . . . . 121
vector (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 382
AFE1_AFE2-1:1
Index
467
AFE1_AFE2-1:1
__iar_cos_accuratef (library routine) . . . . . . . . . . . . . . . . 134 __iar_Sin_small (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_cos_accuratel (library routine) . . . . . . . . . . . . . . . . 134 __iar_sin_small (library routine). . . . . . . . . . . . . . . . . . . . 133
__iar_cos_small (library routine) . . . . . . . . . . . . . . . . . . . 133 __iar_Sin_smallf (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_cos_smallf (library routine) . . . . . . . . . . . . . . . . . . . 133 __iar_sin_smallf (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_cos_smalll (library routine) . . . . . . . . . . . . . . . . . . . 133 __iar_Sin_smalll (library routine) . . . . . . . . . . . . . . . . . . . 133
__IAR_DLIB_PERTHREAD_INIT_SIZE (macro) . . . . . 158 __iar_sin_smalll (library routine) . . . . . . . . . . . . . . . . . . . 133
__IAR_DLIB_PERTHREAD_SIZE (macro) . . . . . . . . . . 158 __IAR_SYSTEMS_ICC__ (predefined symbol) . . . . . . . 372
__IAR_DLIB_PERTHREAD_SYMBOL_OFFSET __iar_tan_accurate (library routine) . . . . . . . . . . . . . . . . . 134
(symbolptr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 __iar_tan_accuratef (library routine). . . . . . . . . . . . . . . . . 134
__iar_exp_small (library routine) . . . . . . . . . . . . . . . . . . . 133 __iar_tan_accuratel (library routine) . . . . . . . . . . . . . . . . . 134
__iar_exp_smallf (library routine) . . . . . . . . . . . . . . . . . . 133 __iar_tan_small (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_exp_smalll (library routine) . . . . . . . . . . . . . . . . . . 133 __iar_tan_smallf (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_log_small (library routine) . . . . . . . . . . . . . . . . . . . 133 __iar_tan_smalll (library routine) . . . . . . . . . . . . . . . . . . . 133
__iar_log_smallf (library routine) . . . . . . . . . . . . . . . . . . . 133 __interrupt (extended keyword) . . . . . . . . . . . . . . . . . 74, 323
__iar_log_smalll (library routine) . . . . . . . . . . . . . . . . . . . 133 using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 354
__iar_log10_small (library routine) . . . . . . . . . . . . . . . . . 133 __intrinsic (extended keyword). . . . . . . . . . . . . . . . . . . . . 324
__iar_log10_smallf (library routine) . . . . . . . . . . . . . . . . . 133 __LINE__ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 372
__iar_log10_smalll (library routine) . . . . . . . . . . . . . . . . . 133 __low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
__iar_Pow (library routine) . . . . . . . . . . . . . . . . . . . . . . . . 134 initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
__iar_Powf (library routine) . . . . . . . . . . . . . . . . . . . . . . . 134 __low_level_init, customizing . . . . . . . . . . . . . . . . . . . . . 138
__iar_Powl (library routine) . . . . . . . . . . . . . . . . . . . . . . . 134 __low_power_mode_n (intrinsic function) . . . . . . . . . . . . 364
__iar_Pow_accurate (library routine) . . . . . . . . . . . . . . . . 134 __low_power_mode_off_on_exit (intrinsic function) . . . . 364
__iar_pow_accurate (library routine) . . . . . . . . . . . . . . . . 134 __memory_of
__iar_Pow_accuratef (library routine) . . . . . . . . . . . . . . . 134 operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
__iar_pow_accuratef (library routine). . . . . . . . . . . . . . . . 134 symbol used in library . . . . . . . . . . . . . . . . . . . . . . . . . 385
__iar_Pow_accuratel (library routine). . . . . . . . . . . . . . . . 134 __monitor (extended keyword) . . . . . . . . . . . . . . . . . . . . . 324
__iar_pow_accuratel (library routine) . . . . . . . . . . . . . . . . 134 __noreturn (extended keyword) . . . . . . . . . . . . . . . . . . . . 327
__iar_pow_small (library routine) . . . . . . . . . . . . . . . . . . 133 __no_alloc (extended keyword) . . . . . . . . . . . . . . . . . . . . 324
__iar_pow_smallf (library routine) . . . . . . . . . . . . . . . . . . 133 __no_alloc_str (operator) . . . . . . . . . . . . . . . . . . . . . . . . . 325
__iar_pow_smalll (library routine) . . . . . . . . . . . . . . . . . . 133 __no_alloc_str16 (operator) . . . . . . . . . . . . . . . . . . . . . . . 325
__iar_program_start (label). . . . . . . . . . . . . . . . . . . . . . . . 135 __no_alloc16 (extended keyword) . . . . . . . . . . . . . . . . . . 324
__iar_Sin (library routine) . . . . . . . . . . . . . . . . . . . . 133–134 __no_init (extended keyword) . . . . . . . . . . . . . . . . . 251, 326
__iar_Sinf (library routine) . . . . . . . . . . . . . . . . . . . . 133–134 __no_multiplier (extended keyword) . . . . . . . . . . . . . . . . 326
__iar_Sinl (library routine) . . . . . . . . . . . . . . . . . . . . 133–134 __no_operation (intrinsic function) . . . . . . . . . . . . . . . . . . 364
__iar_Sin_accurate (library routine) . . . . . . . . . . . . . . . . . 134 __no_pic (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 326
__iar_sin_accurate (library routine) . . . . . . . . . . . . . . . . . 134 __op_code (intrinsic function) . . . . . . . . . . . . . . . . . . . . . 364
__iar_Sin_accuratef (library routine) . . . . . . . . . . . . . . . . 134 __persistent (extended keyword) . . . . . . . . . . . . . . . . . . . 327
__iar_sin_accuratef (library routine) . . . . . . . . . . . . . . . . . 134 cannot be used with ROPI . . . . . . . . . . . . . . . . . . . . . . . 80
__iar_Sin_accuratel (library routine) . . . . . . . . . . . . . . . . 134 __POSITION_INDEPENDENT_CODE__ (predefined
__iar_sin_accuratel (library routine) . . . . . . . . . . . . . . . . . 134 symbol) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
AFE1_AFE2-1:1
Index
469
AFE1_AFE2-1:1
--misrac_verbose (compiler option) . . . . . . . . . . . . . . . . . 267 --version (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 300
--misrac1998 (compiler option) . . . . . . . . . . . . . . . . . . . . 267 --vla (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
--misrac2004 (compiler option) . . . . . . . . . . . . . . . . . . . . 267 --warnings_affect_exit_code (compiler option) . . . . 259, 301
--module_name (compiler option) . . . . . . . . . . . . . . . . . . 285 --warnings_are_errors (compiler option) . . . . . . . . . . . . . 301
--multiplier (compiler option) . . . . . . . . . . . . . . . . . . . . . . 285 --warn_about_c_style_casts (compiler option) . . . . . . . . . 301
--no_call_frame_info (compiler option) . . . . . . . . . . . . . . 286 ?C_EXIT (assembler label) . . . . . . . . . . . . . . . . . . . . . . . . 167
--no_code_motion (compiler option) . . . . . . . . . . . . . . . . 286 ?C_GETCHAR (assembler label) . . . . . . . . . . . . . . . . . . . 167
--no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 286 ?C_PUTCHAR (assembler label) . . . . . . . . . . . . . . . . . . . 167
--no_inline (compiler option) . . . . . . . . . . . . . . . . . . . . . . 287 @ (operator)
--no_path_in_file_macros (compiler option). . . . . . . . . . . 287 placing at absolute address . . . . . . . . . . . . . . . . . . . . . . 237
--no_rw_dynamic_init (compiler option) . . . . . . . . . . . . . 287 placing in segments . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
--no_size_constraints (compiler option) . . . . . . . . . . . . . . 288 #include files, specifying . . . . . . . . . . . . . . . . . . . . . 256, 282
--no_static_destruction (compiler option) . . . . . . . . . . . . . 288 #warning message (preprocessor extension) . . . . . . . . . . . 375
--no_system_include (compiler option) . . . . . . . . . . . . . . 288 %Z replacement string, implementation-defined behavior 426
--no_typedefs_in_diagnostics (compiler option) . . . . . . . . 289
--no_ubrof_messages (compiler option) . . . . . . . . . . . . . . 290
--no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 290 Numerics
--no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 290 32-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 308
--no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 290 64-bit data types, avoiding . . . . . . . . . . . . . . . . . . . . . . . . 233
--omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 291 64-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 308
--only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 292
--output (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . 292
--pending_instantiations (compiler option) . . . . . . . . . . . . 292
--predef_macro (compiler option) . . . . . . . . . . . . . . . . . . . 293
--preinclude (compiler option) . . . . . . . . . . . . . . . . . . . . . 293
--preprocess (compiler option) . . . . . . . . . . . . . . . . . . . . . 293
--reduce_stack_usage (compiler option) . . . . . . . . . . . . . . 294
--regvar_r4 (compiler option) . . . . . . . . . . . . . . . . . . . . . . 294
--regvar_r5 (compiler option) . . . . . . . . . . . . . . . . . . . . . . 295
--relaxed_fp (compiler option) . . . . . . . . . . . . . . . . . . . . . 295
--remarks (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 296
--require_prototypes (compiler option) . . . . . . . . . . . . . . . 296
--ropi (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 296
--save_reg20 (compiler option) . . . . . . . . . . . . . . . . . . . . . 297
--segment (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 297
--silent (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 299
--strict (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 299
--system_include_dir (compiler option) . . . . . . . . . . . . . . 299
--use_c++_inline (compiler option) . . . . . . . . . . . . . . . . . 300
AFE1_AFE2-1:1