EWAVR CompilerGuide PDF
EWAVR CompilerGuide PDF
EWAVR CompilerGuide PDF
User Guide
CAVR-10b
COPYRIGHT NOTICE
© 1996–2017 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, IAR Connect, C-SPY, C-RUN, C-STAT,
IAR Visual State, visualSTATE, 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.
Atmel and AVR are registered trademarks of Microchip Technology.
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
Tenth edition: April 2017
Part number: CAVR-10b
This guide applies to version 7.1x of IAR Embedded Workbench® for Microchip
Technology’s AVR microcontroller family.
Internal reference: M23, Mym8.0, IMAE.
AFE1_AFE2-1:1
Brief contents
Tables ..................................................................................................................... 21
Preface .................................................................................................................... 23
Functions ............................................................................................................... 63
AFE1_AFE2-1:1
Pragma directives ........................................................................................... 319
AFE1_AFE2-1:1
Contents
Tables ..................................................................................................................... 21
Preface .................................................................................................................... 23
Who should read this guide ............................................................... 23
How to use this guide .......................................................................... 23
What this guide contains ................................................................... 24
Other documentation ........................................................................... 25
Document conventions ........................................................................ 28
Introduction ............................................................................................. 53
Memory types ......................................................................................... 54
Introduction to memory types ............................................................ 54
Using data memory attributes ............................................................ 54
Pointers and memory types ................................................................ 56
Structures and memory types ............................................................ 57
AFE1_AFE2-1:1
More examples ................................................................................... 57
C++ and memory types ..................................................................... 58
Memory models ...................................................................................... 59
Specifying a memory model .............................................................. 59
Storage of auto variables and parameters .................................. 60
Dynamic memory on the heap ........................................................ 61
Functions ............................................................................................................... 63
AFE1_AFE2-1:1
Contents
AFE1_AFE2-1:1
Customizing system initialization ................................................. 147
C-SPY emulated I/O ........................................................................... 147
Assembler language interface ................................................................. 149
AFE1_AFE2-1:1
Contents
AFE1_AFE2-1:1
--diag_error ...................................................................................... 245
--diag_remark ................................................................................... 245
--diag_suppress ................................................................................ 246
--diag_warning ................................................................................. 246
--diagnostics_tables .......................................................................... 246
--disable_all_program_memory_load_instructions ......................... 247
--disable_direct_mode ...................................................................... 247
--disable_library_knowledge ........................................................... 247
--disable_mul ................................................................................... 247
--disable_spm ................................................................................... 248
--discard_unused_publics ................................................................. 248
--dlib ................................................................................................. 248
--dlib_config ..................................................................................... 249
--do_cross_call ................................................................................. 250
-e ...................................................................................................... 250
--ec++ ............................................................................................... 250
--eec++ ............................................................................................. 251
--eecr_address .................................................................................. 251
--eeprom_size ................................................................................... 251
--enable_external_bus ...................................................................... 252
--enable_multibytes .......................................................................... 252
--enable_restrict ............................................................................... 253
--enhanced_core ............................................................................... 253
--error_limit ...................................................................................... 253
-f ....................................................................................................... 254
--force_switch_type ......................................................................... 254
--guard_calls ..................................................................................... 255
--header_context ............................................................................... 255
-I ....................................................................................................... 255
--initializers_in_flash ....................................................................... 256
-l ....................................................................................................... 256
--library_module .............................................................................. 257
--lock_regs ....................................................................................... 258
--macro_positions_in_diagnostics ................................................... 258
AFE1_AFE2-1:1
Contents
11
AFE1_AFE2-1:1
--segment .......................................................................................... 271
--separate_cluster_for_initialized_variables .................................... 272
--silent .............................................................................................. 272
--spmcr_address ............................................................................... 273
--strict ............................................................................................... 273
--string_literals_in_flash .................................................................. 273
--system_include_dir ........................................................................ 274
--use_c++_inline .............................................................................. 274
-v ...................................................................................................... 275
--version ........................................................................................... 276
--version1_calls ................................................................................ 276
--version2_calls ................................................................................ 277
--vla .................................................................................................. 277
--warn_about_c_style_casts ............................................................. 277
--warnings_affect_exit_code ............................................................ 278
--warnings_are_errors ...................................................................... 278
--xmcra_address ............................................................................... 278
-y ...................................................................................................... 279
-z ....................................................................................................... 279
--zero_register .................................................................................. 280
AFE1_AFE2-1:1
Contents
13
AFE1_AFE2-1:1
__x_z ................................................................................................ 316
__z .................................................................................................... 317
__z_x ................................................................................................ 317
AFE1_AFE2-1:1
Contents
15
AFE1_AFE2-1:1
__save_interrupt .............................................................................. 348
__set_interrupt_state ........................................................................ 348
__sleep ............................................................................................ 349
__swap_nibbles ................................................................................ 349
__watchdog_reset ............................................................................ 349
__xch ................................................................................................ 349
AFE1_AFE2-1:1
Contents
__ICC avr __
..................................................................................... 356
__LINE__ ........................................................................................ 356
__LITTLE_ENDIAN__ .................................................................. 356
__MEMORY_MODEL__ ............................................................... 356
__PRETTY_FUNCTION__ ............................................................ 356
__STDC__ ....................................................................................... 357
__STDC_VERSION__ ................................................................... 357
__SUBVERSION__ ........................................................................ 357
__TID__ .......................................................................................... 357
__TIME__ ....................................................................................... 358
__TIMESTAMP__ .......................................................................... 358
__TINY_AVR__ ............................................................................. 358
__VER__ ......................................................................................... 358
__VERSION_1_CALLS__ ............................................................. 358
__XMEGA_CORE__ ...................................................................... 359
__XMEGA_USB__ ......................................................................... 359
Descriptions of miscellaneous preprocessor extensions ..... 359
NDEBUG ........................................................................................ 359
#warning message ........................................................................... 360
17
AFE1_AFE2-1:1
strcat_G ............................................................................................ 372
strcmp_G .......................................................................................... 372
strcmp_P ........................................................................................... 373
strcpy_G ........................................................................................... 373
strcpy_P ............................................................................................ 373
strerror_P .......................................................................................... 373
strlen_G ............................................................................................ 373
strlen_P ............................................................................................. 373
strncat_G .......................................................................................... 374
strncmp_G ........................................................................................ 374
strncmp_P ......................................................................................... 374
strncpy_G ......................................................................................... 374
strncpy_P .......................................................................................... 374
AFE1_AFE2-1:1
Contents
19
AFE1_AFE2-1:1
Syntactic components ........................................................................ 395
category ............................................................................................ 395
func-spec .......................................................................................... 395
module-spec ..................................................................................... 396
name ................................................................................................. 396
call-info ............................................................................................ 396
stack-size .......................................................................................... 397
size .................................................................................................... 397
AFE1_AFE2-1:1
Tables
1: Typographic conventions used in this guide ......................................................... 28
2: Naming conventions used in this guide ................................................................ 29
3: Summary of processor configuration .................................................................... 50
4: Memory types and their corresponding memory attributes .................................. 55
5: Memory model characteristics .............................................................................. 59
6: Heaps supported in memory types ........................................................................ 62
7: Function memory attributes .................................................................................. 63
8: XLINK segment memory types ............................................................................ 72
9: segments holding initialized data .......................................................................... 76
10: Debug information and levels of C-SPY emulated I/O .................................... 104
11: Library configurations ....................................................................................... 110
12: Prebuilt libraries ................................................................................................ 113
13: Formatters for printf .......................................................................................... 113
14: Formatters for scanf .......................................................................................... 114
15: DLIB low-level I/O interface functions ............................................................ 123
16: Descriptions of printf configuration symbols ................................................... 132
17: Descriptions of scanf configuration symbols .................................................... 132
18: Library objects using TLS ................................................................................. 136
19: Macros for implementing TLS allocation ......................................................... 139
20: Runtime libraries ............................................................................................... 142
21: Registers used for passing parameters .............................................................. 160
22: Passing parameters in registers ......................................................................... 161
23: Registers used for returning values ................................................................... 162
24: Language extensions ......................................................................................... 169
25: Compiler optimization levels ............................................................................ 215
26: Compiler environment variables ....................................................................... 228
27: Error return codes .............................................................................................. 230
28: Compiler options summary ............................................................................... 235
29: Accessing variables with aggregate initializers ................................................ 256
30: Integer types ...................................................................................................... 282
31: Floating-point types .......................................................................................... 285
21
AFE1_AFE2-1:1
32: Function pointers ............................................................................................... 287
33: Data pointers ..................................................................................................... 287
34: size_t typedef .................................................................................................... 289
35: ptrdif_t typedef .................................................................................................. 290
36: Type of volatile accesses treated in a special way ............................................ 292
37: Extended keywords summary ........................................................................... 299
38: Pragma directives summary .............................................................................. 319
39: Intrinsic functions summary .............................................................................. 341
40: Traditional Standard C header files—DLIB ..................................................... 364
41: C++ header files ................................................................................................ 365
42: Standard template library header files ............................................................... 366
43: New Standard C header files—DLIB ............................................................... 366
44: CLIB runtime environment header files ........................................................... 370
45: Segment summary ............................................................................................. 375
46: Message returned by strerror()—DLIB runtime environment .......................... 414
47: Message returned by strerror()—DLIB runtime environment .......................... 425
48: Message returned by strerror()—CLIB runtime environment .......................... 428
AFE1_AFE2-1:1
Preface
Welcome to the IAR C/C++ Compiler User Guide for AVR. 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 Microchip AVR 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 25.
23
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.
25
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/EC++ 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++: 50 Specific Ways to Improve Your Programs and
Designs. 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 Microchip Technology web site, www.microchip.com, that contains
information and news about the Microchip AVR 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.
27
AFE1_AFE2-1:1
Document conventions
Document conventions
When, in the IAR Systems documentation, we refer to the programming language C, the
text also applies to C++, unless otherwise stated.
When referring to a directory in your product installation, for example avr\doc, the full
path to the location is assumed, for example c:\Program Files\IAR
Systems\Embedded Workbench N.n\avr\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 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 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.
[a|b|c] An optional part of a command with alternatives.
{a|b|c} A mandatory part of a command 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 AVR IAR Embedded Workbench®
IAR Embedded Workbench® IDE for AVR the IDE
IAR C-SPY® Debugger for AVR C-SPY, the debugger
IAR C-SPY® Simulator the simulator
IAR C/C++ Compiler™ for AVR the compiler
IAR Assembler™ for AVR the assembler
IAR XLINK Linker™ XLINK, the linker
IAR XAR Library Builder™ the library builder
IAR XLIB Librarian™ the librarian
IAR DLIB Runtime Environment™ the DLIB runtime environment
IAR CLIB Runtime Environment™ the CLIB runtime environment
Table 2: Naming conventions used in this guide
29
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 AVR includes these
chapters:
● Data storage
● Functions
● Linking overview
● Using C
● Using C++
● Application-related considerations
31
32
Introduction to the IAR
build tools
● The IAR build tools—an overview
● Device support
33
AFE1_AFE2-1:1
IAR language overview
IAR ASSEMBLER
The IAR Assembler for AVR is a powerful relocating macro assembler with a versatile
set of directives and expression operators. The assembler features a built-in C language
preprocessor and supports conditional assembly.
The IAR Assembler for AVR uses the same mnemonics and operand syntax as the
Microchip Technology AVR Assembler, which simplifies the migration of existing
code. For more information, see the IAR Assembler User Guide for AVR.
EXTERNAL TOOLS
For information about how to extend the tool chain in the IDE, see the IDE Project
Management and Building Guide for AVR.
AFE1_AFE2-1:1
Introduction to the IAR build tools
Each of the supported languages can be used in strict or relaxed mode, or relaxed with
IAR extensions enabled. The strict mode adheres to the standard, whereas the relaxed
mode allows some common deviations from the standard.
For more information about C, see the chapter Using C.
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 AVR.
Device support
To get a smooth start with your product development, the IAR product installation
comes with a wide range of device-specific support.
35
AFE1_AFE2-1:1
Special support for embedded systems
linker configuration file, see Placing code and data—the linker configuration file, page
74 as well as the IAR Linker and Library Tools Reference Guide.
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.
By default, language extensions are enabled in the IDE.
The command line option -e makes the extended keywords available, and reserves them
so that they cannot be used as variable names. See, -e, page 250 for additional
information.
For more information about the extended keywords, see the chapter Extended keywords.
See also, Data storage, page 53 and Functions, page 63.
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 very useful when you want to make sure that the source code is
portable.
AFE1_AFE2-1:1
Introduction to the IAR build tools
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.
37
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 on-chip RAM,
external DRAM or SRAM, 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
benefit from being placed here. Conversely, some configuration data might be accessed
seldom but must maintain their value after power off, so they should be saved in
EEPROM or flash memory.
39
AFE1_AFE2-1:1
Developing embedded software using IAR build tools
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 210. 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 74.
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 64.
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.
A C/C++ application further needs to initialize all global variables. This initialization is
handled by the linker and the system startup code in conjunction. For more information,
see Application execution—an overview, page 44.
AFE1_AFE2-1:1
Developing embedded applications
41
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
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.
During the 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.
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.
43
AFE1_AFE2-1:1
Application execution—an overview
This illustration shows the possible uses of the absolute output files:
AFE1_AFE2-1:1
Developing embedded applications
45
AFE1_AFE2-1:1
Application execution—an overview
2 Then, memories that should be zero-initialized are cleared, in other words, filled with
zeros.
Typically, this is data referred to as zero-initialized data; variables declared as, for
example, int i = 0;
3 For initialized data, data declared, for example, like int i = 6; the initializers are
copied from ROM to RAM.
AFE1_AFE2-1:1
Developing embedded applications
For more information about each stage, see System startup and termination, page 118.
For more information about initialization of data, see Initialization at system startup,
page 75.
Note: The AVR microcontroller is based on the Harvard architecture—thus code and
data have separate memory spaces and require different access mechanisms. For more
information, see the chapter Data storage.
47
AFE1_AFE2-1:1
Building applications—an overview
To terminate an application in a controlled way, either call one of the Standard C library
functions exit, _Exit, or abort, or return from main. If you return from main, the
exit function is executed, which means that C++ destructors for static and global
variables are called (C++ only) and all open files are closed.
Of course, in case of incorrect program logic, the application might terminate in an
uncontrolled and abnormal way—a system crash.
For more information about this, see System termination, page 121.
You must also specify some critical options, see Basic project configuration, page 48.
On the command line, this line can be used for starting the linker:
xlink myfile.r90 myfile2.r90 -o a.d90 -f my_configfile.xcl -r
AFE1_AFE2-1:1
Developing embedded applications
PROCESSOR CONFIGURATION
To make the compiler generate optimum code, you should configure it for the AVR
microcontroller you are using.
Your application may only use one processor option at a time, and the same processor
option must be used by all user and library modules to maintain consistency.
Both options set up default behavior—implicit assumptions—but note that the --cpu
option is more precise because it contains more information about the intended target
than the more generic -v option. The --cpu option knows, for example, how much flash
memory is available in the given target.
The --cpu=device option implicitly sets up all internal compiler settings needed to
generate code for the processor variant you are using. These options are implicitly
controlled when you use the --cpu option: --eecr_address, --eeprom_size,
--enhanced_core, --spmcr_address, -v and --64k_flash.
Because these options are automatically set when you use the --cpu option, you cannot
set them explicitly. For information about implicit assumptions when using the -v
option, see Summary of processor configuration for -v, page 50. For more information
about the generated code, see -v, page 275.
Use the --cpu or -v option to specify the AVR device; see the chapter Compiler options
for syntax information.
See the IDE Project Management and Building Guide for AVR for information about
setting project options in the IDE.
49
AFE1_AFE2-1:1
Basic project configuration
Note:
● *) When using the -v5 or the -v6 option, it is possible, for individual functions, to
override the __farfunc attribute and instead use the __nearfunc attribute
● Pointers with function memory attributes have restrictions in implicit and explicit
casts between pointers and between pointers and integer types. For details about the
restrictions, see Casting, page 289.
● -v2: There are currently no devices that match this processor option, which has
been added to support future devices
● All implicit assumptions for a given -v option are also true for corresponding
--cpu options.
It is important to be aware of the fact that the -v option does not reflect the amount of
used data, but the maximum amount of addressable data. This means that, for example,
if you are using a microcontroller with 16 Mbytes addressable data, but you are not
using more than 256 bytes or 64 Kbytes of data, you must still use either the -v4 or the
-v6 option for 16 Mbytes data.
AFE1_AFE2-1:1
Developing embedded applications
51
AFE1_AFE2-1:1
Basic project configuration
AFE1_AFE2-1:1
Data storage
● Introduction
● Memory types
● Memory models
Introduction
The AVR microcontroller is based on the Harvard architecture—thus code and data have
separate memory spaces and require different access mechanisms. Code and different
types of data are located in memory spaces as follows:
● The internal flash space, which is used for code, __flash declared objects, and
initializers
● The data space, which can consist of external ROM, used for constants, and RAM
areas used for the stack, for registers, and for variables
● The EEPROM space, which is used for variables.
53
AFE1_AFE2-1:1
Memory types
useful when the number of objects is not known until the application executes. Note
that there are potential risks connected with using dynamically allocated data in
systems with a limited amount of memory, or systems that are expected to run for a
long time. For more information, see Dynamic memory on the heap, page 61.
Memory types
This section describes the concept of memory types used for accessing data by the
compiler. It also discusses pointers in the presence of multiple memory types. For each
memory type, the capabilities and limitations are discussed.
AFE1_AFE2-1:1
Data storage
This table summarizes the available memory types and their corresponding keywords:
The keywords are only available if language extensions are enabled in the compiler.
In the IDE, language extensions are enabled by default.
Use the -e compiler option to enable language extensions. See -e, page 250 for
additional information.
For more information about each keyword, see Descriptions of extended keywords, page
300.
55
AFE1_AFE2-1:1
Memory types
Syntax
The keywords follow the same syntax as the type qualifiers const and volatile. The
memory attributes are type attributes and therefore they must be specified both when
variables are defined and in the declaration, see General syntax rules for extended
keywords, page 295.
The following declarations place the variables i and j in EEPROM memory. The
variables k and l will also be placed in EEPROM memory. The position of the keyword
does not have any effect in this case:
__eeprom int i, j;
int __eeprom k, l;
Note that the keyword affects both identifiers. If no memory type is specified, the default
memory type is used.
The #pragma type_attribute directive can also be used for specifying the memory
attributes. The advantage of using pragma directives for specifying keywords is that it
offers you a method to make sure that the source code is portable. Refer to the chapter
Pragma directives for details about how to use the extended keywords together with
pragma directives.
Type definitions
Storage can also be specified using type definitions. These two declarations are
equivalent:
/* Defines via a typedef */
typedef char __far Byte;
typedef Byte *BytePtr;
Byte aByte;
BytePtr aBytePointer;
/* Defines directly */
__far char aByte;
char __far *aBytePointer;
AFE1_AFE2-1:1
Data storage
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 near memory.
Like MyPtr, MyPtr2 points to a character in far memory.
char __far * __near MyPtr2;
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
57
AFE1_AFE2-1:1
Memory types
AFE1_AFE2-1:1
Data storage
Memory models
Technically, the memory model specifies the default memory type attribute and the
default data pointer attribute. This means that the memory model controls the following:
● The default placement of static and global variables, and constant literals
● Dynamically allocated data, for example data allocated with malloc, or, in C++,
the operator new
● The default pointer type
● The placement of the runtime stack. For details about stack placement, see
CSTACK, page 378.
For information about how to specify a memory type for individual objects, see Using
data memory attributes, page 54.
Default
Memory Default data Supported by
memory Max. stack range
model pointer processor option
attribute
Tiny __tiny __tiny <= 256 bytes in the range 0-FF -v0, -v1, -v2,
-v3, -v5
Small __near __near <= 64 Kbytes in the range 0-FFFF -v1, -v3, -v4,
-v5, -v6
Table 5: Memory model characteristics
59
AFE1_AFE2-1:1
Storage of auto variables and parameters
Default
Memory Default data Supported by
memory Max. stack range
model pointer processor option
attribute
Large __far __far <= 64 Kbytes in the range -v4, -v6
0-FFFFFF, but never cross a
64-Kbyte boundary
Huge __huge __huge <= 64 Kbytes in the range -v4, -v6
0-FFFFFF, but never cross a
64-Kbyte boundary
Table 5: Memory model characteristics (Continued)
See the IDE Project Management and Building Guide for AVR for information about
setting options in the IDE.
Use the --memory_model option to specify the memory model for your project; see
--memory_model, -m, page 258.
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
AFE1_AFE2-1:1
Data storage
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.
61
AFE1_AFE2-1:1
Dynamic memory on the heap
In C++, a special keyword, new, allocates memory and runs constructors. Memory
allocated with new must be released using the keyword delete.
The compiler supports heaps in more than one memory types:
Used by default in
Memory type Memory attribute Section name
memory model
tiny __tiny TINY_HEAP Tiny
near __near NEAR_HEAP Small
far __far FAR_HEAP Large
huge __huge HUGE_HEAP Huge
Table 6: 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 __near_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 92.
POTENTIAL PROBLEMS
Applications that use heap-allocated data objects must be very carefully designed,
because 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
● Function storage
● 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 the storage of functions in memory
● 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 205. For information about the available intrinsic functions for
accessing hardware operations, see the chapter Intrinsic functions.
Function storage
USING FUNCTION MEMORY ATTRIBUTES
It is possible to override the default placement for individual functions. Use the
appropriate function memory attribute to specify this. These attributes are available:
63
AFE1_AFE2-1:1
Primitives for interrupts, concurrency, and OS-related programming
When using the -v5 or the -v6 option, it is possible, for individual functions, to override
the __farfunc attribute and instead use the __nearfunc attribute. The default
memory can be overridden by explicitly specifying a memory attribute in the function
declaration or by using the #pragma type_attribute directive:
#pragma type_attribute=__nearfunc
void MyFunc(int i)
{
...
}
It is possible to call a __nearfunc function from a __farfunc function and vice versa.
Only the size of the function pointer is affected.
It is possible to place functions into named segments using either the @ operator or the
#pragma location directive. For more information, see Controlling data and function
placement in memory, page 210.
Pointers with function memory attributes have restrictions in implicit and explicit casts
between pointers and between pointers and integer types. For information about the
restrictions, see Casting, page 289.
For syntax information and for more information about each attribute, see the chapter
Extended keywords.
INTERRUPT FUNCTIONS
In embedded systems, using interrupts is a method for handling external events
immediately; for example, detecting that a button was pressed.
AFE1_AFE2-1:1
Functions
register). This makes it possible to continue the execution of the original code after the
code that handled the interrupt was executed.
The AVR microcontroller supports many interrupt sources. For each interrupt source, an
interrupt routine can be written. Each interrupt routine is associated with a vector
number, which is specified in the AVR microcontroller documentation from the chip
manufacturer. If you want to handle several different interrupts using the same interrupt
routine, you can specify several interrupt vectors.
Note: An interrupt function must have the return type void, and it cannot specify any
parameters.
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.
65
AFE1_AFE2-1:1
Primitives for interrupts, concurrency, and OS-related programming
To define a monitor function, you can use the __monitor keyword. For more
information, see __monitor, page 308.
Avoid using the __monitor keyword on large functions, since the interrupt will
otherwise be turned off for too long.
sTheLock = 1;
return 1;
}
else
{
/* Failure, someone else has the lock. */
return 0;
}
}
AFE1_AFE2-1:1
Functions
void GetLock(void)
{
while (!TryGetLock())
{
/* Normally, a sleep instruction is used here. */
}
}
void MyProgram(void)
{
GetLock();
/* Do something here. */
ReleaseLock();
}
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.
67
AFE1_AFE2-1:1
Inlining functions
AFE1_AFE2-1:1
Functions
69
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. Further, 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.
71
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 that denotes the type of content. 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
XLINK supports more segment memory types than the ones described above. However,
they exist to support other types of microcontrollers.
For more information about individual segments, see the chapter Segment reference.
73
AFE1_AFE2-1:1
Placing code and data—the linker configuration file
● Optionally, produces a map file that lists the result of the segment placement, the
address of each global symbol, and finally, a summary of memory usage for each
module.
This illustration shows the linking process:
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
75
AFE1_AFE2-1:1
Initialization at system startup
● Variables that are located by use of the @ operator or the #pragma location
directive
● Variables that are declared as const and therefore can be stored in ROM
● Variables defined with the __no_init keyword, meaning that they should not be
initialized at all.
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
Non-initialized __no_init int i; Read/write MEMATTR_N None
data data
Data placed in __memattr int i Read-only data MEMATTR_F The constant
flash memory = 6;
Table 9: segments holding initialized data
AFE1_AFE2-1:1
Linking overview
The initializers are copied to the b variable allocated on the stack each time the function
is entered.
77
AFE1_AFE2-1:1
Initialization at system startup
The initializers can either come from the code memory space (flash) or from the data
memory space (optional external ROM). By default, the initializers are located in
segments with the suffix _C and these segments are copied from external ROM to the
stack.
If you use either the -y option or the --initializers_in_flash option, the
aggregate initializers are located in segments with the suffix _F, which are copied from
flash memory to the stack. The advantage of storing these initializers in flash is that
valuable data space is not wasted. The disadvantage is that copying from flash is slower.
AFE1_AFE2-1:1
Linking overview
79
AFE1_AFE2-1:1
Stack usage analysis
3 Link your project. Note that the linker will issue warnings related to stack usage under
certain circumstances, see Situations where warnings are issued, page 84.
4 Review the linker map file, which now contains a stack usage chapter with a summary
of the stack usage for each call graph root. For more information, see Result of an
analysis—the map file contents, page 80.
5 For more details, analyze the call graph log, see Call graph log, page 84.
Note that there are limitations and sources of inaccuracy in the analysis, see Limitations,
page 83.
You might need to specify more information to the linker to get a more representative
result. See Specifying additional stack usage information, page 82
In the IDE, choose Project>Options>Linker>Advanced>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",
CSTACK) + totalstack("interrupt", CSTACK) + 100;
or
check that size("MY_STACK") >=maxstack("Program entry",
RSTACK) + totalstack("interrupt", RSTACK) + 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 392 and Stack considerations, page 193.
AFE1_AFE2-1:1
Linking overview
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
81
AFE1_AFE2-1:1
Stack usage analysis
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.
AFE1_AFE2-1:1
Linking overview
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 391 and call_graph_root, page 322.
● 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.r90] 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 AVR.
For more information, see the chapter The stack usage control file, page 391.
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 assembly language. You can provide stack usage information for such
modules using a stack usage control file, and for assembly 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 AVR.
● 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.
83
AFE1_AFE2-1:1
Stack usage analysis
● 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 that 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.
AFE1_AFE2-1:1
Linking overview
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]
85
AFE1_AFE2-1:1
Stack usage analysis
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]
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
87
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 near memory and one for far
memory.
● There is one stack and one heap.
● There are two addressing modes for code, one for nearfunc memory and one for
farfunc 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 continuous 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.
89
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.
Note: The AVR microcontroller is based on the Harvard architecture—thus code and
data have separate memory spaces and require different access mechanisms. For more
information, see the chapter Data storage.
PLACING DATA
Static memory is memory that contains variables that are global or declared static.
To get a clear understanding about how the data segments work, you must be familiar
with the different memory types and the different memory models available in the
compiler. For information about these details, see the chapter Data storage.
All the data segments are placed in the area used by on-chip RAM.
AFE1_AFE2-1:1
Linking your application
location in the memory space, and it does not have to be specified in the linker
configuration file.
Note that the size is written hexadecimally, but not necessarily with the 0x notation.
Note:
● This range does not specify the size of the stack; it specifies the range of the
available memory.
● The = allocates the CSTACK segment at the start of the memory area.
91
AFE1_AFE2-1:1
Linking considerations
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.
Note: This range does not specify the size of the heap; it specifies the range of the
available memory.
AFE1_AFE2-1:1
Linking your application
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 375.
Normal code
Depending on their memory attribute, functions are placed in various segments, in this
example NEARFUNC and FARFUNC.
Placing the segments is a simple operation in the linker configuration file:
-P(CODE)NEARFUNC=0000-1FFF,3000-4FFF
-P(CODE)FARFUNC=0000-1FFF,3000-4FFF,10000-1FFFF
Here, the -P linker directive is used for allowing XLINK to split up the segments and
pack their contents more efficiently. This is also useful if the memory range is
non-continuous.
For information about segments holding normal code, see the chapter Segment
reference.
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. The linker directive
would then look like this:
-Z(CONST)INTVEC=0000-00FF
For more information about the interrupt vectors, see Interrupt vectors and the interrupt
vector table, page 65.
DIFUNCT must be placed using -Z. For more information, see DIFUNCT, page 378.
93
AFE1_AFE2-1:1
Linking considerations
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
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 -A to make all modules in the
file be treaded as if they were program modules:
-A file.r90
Use -C to makes all modules in the file be treated as if they were library modules:
-C file.r90
AFE1_AFE2-1:1
Linking your application
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 reset vector. 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.
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.
95
AFE1_AFE2-1:1
Verifying the linked result of code and data placement
AFE1_AFE2-1:1
Linking your application
are placing objects in EEPROM or an external ROM in DATA space, the output format
cannot represent this, and the linker issues this error message:
Error[e133]: The output format Format cannot handle multiple
address spaces. Use format variants (-y -O) to specify which
address space is wanted.
To limit the output to flash memory, make a copy of the linker configuration file for the
derivative and memory model you are using, and put it in the project directory. Add this
line to the file:
-y(CODE)
To produce output for the other memory space(s), you must generate one output file per
memory space (because the output format you chose does not support more than one
memory space). Use the XLINK option -O for this purpose.
For each additional output file, you must specify format, XLINK segment type, and file
name. For example:
-Omotorola,(DATA)=external_rom.a90
-Omotorola,(XDATA)=eeprom.a90
Note: As a general rule, an output file is only necessary if you use non-volatile memory.
In other words, output from the data space is only necessary if the data space contains
external ROM.
For more information, see the IAR Linker and Library Tools Reference Guide.
97
AFE1_AFE2-1:1
Verifying the linked result of code and data placement
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.
99
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:
101
AFE1_AFE2-1:1
Introduction to the runtime environment
AFE1_AFE2-1:1
The DLIB runtime environment
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 107. See also The DLIB low-level I/O interface,
page 123 for information about the functions that are part of the interface.
103
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.
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 runtime -r The same as -Fubrof but also limited support for
control modules C-SPY emulated I/O handling program abort, exit,
and assertions.
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 AVR.
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.
For more information, see Math functions, page 116.
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 110.
You have now set up a runtime environment that can be used while developing your
application source code.
105
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 107.
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 102.
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. Also, note that the NDEBUG symbol is
defined in a Release build configuration, which means asserts will no longer be
generated. For more information, see _ReportAssert, page 129.
107
AFE1_AFE2-1:1
Setting up the runtime environment
3 Add the modified file to your project, like any other source file.
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 102.
You have now finished the process of overriding the library module with your version.
AFE1_AFE2-1:1
The DLIB runtime environment
these files, make copies of them first and replace the original files in the project with
these copies.
2 Modify the project options in the created library project to suit your application, see
Basic project configuration, page 48.
To customize the library functionality:
1 The library functionality is determined by a set of configuration symbols. The default
values of these symbols are defined in the file DLib_Defaults.h which you can find
in avr\inc\DLIB\c. This read-only file describes the configuration possibilities.
Note that you should not modify this file.
In addition, your custom library has its own library configuration file
dlavrCustom.h—which you can find in avr\config\template\project—and
which sets up that specific library with the required library configuration. Customize
this file by setting the values of the configuration symbols according to the application
requirements. For example, to enable the ll qualifier in printf format strings, write in
your library configuration file:
#define _DLIB_PRINTF_LONG_LONG 1
For information about configuration symbols that you might want to customize, see:
● Configuration symbols for printf and scanf, page 132
● Configuration symbols for file input and output, page 133
● Locale, page 133
● Strtod, page 135
● Managing a multithreaded environment, page 135
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). There is also a batch file
(build_libs.bat) provided for building the library from the command line. For
information about the build process and the IAR Command Line Build Utility, see the
IDE Project Management and Building Guide for AVR.
To use the customized runtime library in your application project:
1 In the IDE, choose Project>Options>General Options and click the Library
Configuration tab.
2 From the Library drop-down menu, choose Custom DLIB.
3 In the Library file text box, locate your library file.
109
AFE1_AFE2-1:1
Additional information on the runtime environment
4 In the Configuration file text box, locate your library configuration file.
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 108
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 your runtime environment,
page 104.
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 249.
The prebuilt libraries are based on the default configurations, see Runtime library
configurations, page 110.
2 If you have built your own customized library, choose Project>Options>Library
Configuration>Library and choose Custom to use your own configuration. For more
information, see Customizing and building your own runtime library, page 108.
111
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 files in the subdirectory avr\lib\dlib and the library
configuration files in the avr\inc\dlib subdirectory.
{target} is avr
{memModel} Specifies the memory model:
t = Tiny
s = Small
l = Large
h = Huge
AFE1_AFE2-1:1
The DLIB runtime environment
113
AFE1_AFE2-1:1
Additional information on the runtime environment
analysis, forcing the linker to select the Full formatter. In this case, you might want to
override the automatically selected printf formatter.
To override the automatically selected printf 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 override the automatically selected printf formatter from the command
line:
1 Add one of these lines in the linker configuration file you are using:
-e_PrintfFull=_Printf
-e_PrintfFullNoMb=_Printf
-e_PrintfLarge=_Printf
-e_PrintfLargeNoMb=_Printf
_e_PrintfSmall=_Printf
-e_PrintfSmallNoMb=_Printf
-e_PrintfTiny=_Printf
-e_PrintfTinyNoMb=_Printf
To override the default AVR-specific printf_P formatter, type any of the following
lines in your linker command file:
-e_small_write_P=_formatted_write_P
-e_medium_write_P=_formatted_write_P
AFE1_AFE2-1:1
The DLIB runtime environment
To override the default AVR-specific scanf_P formatter, type the following line in your
linker command file:
-e_medium_read_P=_formatted_read_P
115
AFE1_AFE2-1:1
Additional information on the runtime environment
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).
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.
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.
117
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 122.
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.
● The external data and address buses are enabled if needed.
● The stack pointers are initialized to the end of CSTACK and RSTACK, respectively.
● The function _ _low_level_init is called if you defined it, giving the application
a chance to perform early initializations.
119
AFE1_AFE2-1:1
Additional information on the runtime environment
● Static and global variables are initialized except for _ _no_init, _ _tinyflash,
_ _flash, _ _farflash, _ _hugeflash, and _ _eeprom declared variables. That is,
zero-initialized variables are cleared and the values of other initialized variables are
copied from ROM to RAM memory. This step is skipped if _ _low_level_init
returns zero. For more information, see Initialization at system startup, page 75.
● Static C++ objects are constructed
● The main function is called, which starts the application.
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:
121
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
avr\src\lib directory. See Overriding library modules, page 107.
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 file cstartup before the data segments are initialized.
Modifying the file cstartup.s90 directly should be avoided.
The code for handling system startup is located in the source files cstartup.s90 and
low_level_init.c, located in the avr\src\lib directory.
Note: Normally, you do not need to customize either of the files cstartup.s90 or
_exit.s90.
Customizing _ _low_level_init
You can customize the routine _ _low_level_init, which is called from the system
startup code before the data segments are initialized.
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 that you must make sure that the linker uses the start label used in your version of
cstartup.s90. 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
123
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 102.
abort
Source file avr\src\lib\abort.c
C-SPY debug action Notifies that the application has called abort.
clock
Source file avr\src\lib\clock.c
__close
Source file avr\src\lib\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 avr\src\lib\xxexit.c
C-SPY debug action Notifies that the end of the application was reached.
getenv
Source file avr\src\lib\getenv.c
avr\src\lib\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.
125
AFE1_AFE2-1:1
Additional information on the runtime environment
__getzone
Source file avr\src\lib\getzone.c
__lseek
Source file avr\src\lib\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 avr\src\lib\open.c
AFE1_AFE2-1:1
The DLIB runtime environment
raise
Source file avr\src\lib\raise.c
Default implementation Calls the signal handler for the raised signal, or terminates with call to
_ _exit(EXIT_FAILURE).
__read
Source file avr\src\lib\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.
127
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 106.
For information about the @ operator, see Controlling data and function placement in
memory, page 210.
remove
Source file avr\src\lib\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 avr\src\lib\rename.c
_ReportAssert
Source file avr\src\lib\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 359.
signal
Source file avr\src\lib\signal.c
129
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 avr\src\lib\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 avr\src\lib\time.c
avr\src\lib\time64.c
__write
Source file avr\src\lib\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 106.
131
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 110.
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.
133
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 108.
135
AFE1_AFE2-1:1
Managing a multithreaded environment
The low-level implementations of locks and TLS are system-specific, and is not
included in the DLIB runtime environment. If you are using an RTOS, check if it
provides some or all of the required functions. Otherwise, you must provide your own.
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.
AFE1_AFE2-1:1
The DLIB runtime environment
137
AFE1_AFE2-1:1
Managing a multithreaded 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.
AFE1_AFE2-1:1
The DLIB runtime environment
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.
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 19: Macros for implementing TLS allocation
139
AFE1_AFE2-1:1
Managing a multithreaded environment
Note that the size needed for TLS variables depends on which resources in the DLIB
runtime environment your application uses.
This is an example of how you can handle threads:
#include <yvals.h>
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.
AFE1_AFE2-1:1
The CLIB runtime
environment
● Using a prebuilt runtime library
Note that 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++.
For information about migrating from CLIB to DLIB, see the IAR Embedded
Workbench® Migration Guide.
141
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
● {type} cl for the CLIB runtime library
● {cpu} is a value from 0 to 6, matching the -v option
● {memModel} is one of t, s, l, or h for the Tiny, Small, Large, or Huge memory
model, respectively
● {smallFlash} is sf when the small flash memory is available. When small flash
memory is not available, this value is not specified
● {64BitDoubles} is 64 when 64-bit doubles are used. When 32-bit doubles are
used, this value is not specified.
These are some examples of how to decode a library name:
Generic
Memory 64-bit
Library file processor Core Small flash
model doubles
option
cl0t.r90 -v0 Tiny -- -- --
cl1s-64.r90 -v1 Small -- -- X
cl61-ec_mul-64.r90 -v6 Large X -- X
Table 20: Runtime libraries
AFE1_AFE2-1:1
The CLIB runtime environment
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.
The creation of new I/O routines is based on these files:
● putchar.c, which serves as the low-level part of functions such as printf
● getchar.c, which serves as the low-level part of functions such as scanf.
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 @ 40;
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 107.
_large_write
_medium_write
_small_write
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.
143
AFE1_AFE2-1:1
Input and output
_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:
_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 107.
AFE1_AFE2-1:1
The CLIB runtime environment
By default, the linker automatically uses the most appropriate formatter for your
application.
_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.
145
AFE1_AFE2-1:1
Overriding default library modules
SYSTEM STARTUP
When an application is initialized, several steps are performed:
● The custom function __low_level_init is called, giving the application a chance
to perform early initializations
● The external data and address buses are enabled if needed
● The stack pointers are initialized to the end of CSTACK and RSTACK, respectively
● Static variables are initialized except for __no_init __tinyflash, __flash,
__farflash, __hugeflash, and __eeprom declared variables; this includes
clearing zero-initialized memory and copying the ROM image of the RAM memory
of the remaining initialized variables
● The main function is called, which starts the application.
Note that the system startup code contains code for more steps than described here. The
other steps are applicable to the DLIB runtime environment.
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.
147
AFE1_AFE2-1:1
C-SPY emulated I/O
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 very 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
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.
149
AFE1_AFE2-1:1
Mixing C and assembler
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 152, and Calling assembler routines from
C++, page 154, respectively.
INLINE ASSEMBLER
Inline assembler can be used for inserting assembler instructions directly into a C or
C++ function.
The asm extended keyword and its alias __asm both insert assembler instructions.
However, when you compile C source code, the asm keyword is not available when the
option --strict is used. The __asm keyword is always available.
Note: Not all assembler directives or operators can be inserted using these keywords.
The syntax is:
asm ("string");
The string can be a valid assembler instruction or a data definition assembler directive,
but not a comment. You can write several consecutive inline assembler instructions, for
example:
asm("label:nop\n"
"jmp label");
where \n (new line) separates each new assembler instruction. Note that you can define
and use local labels in inline assembler instructions.
The following example demonstrates the use of the asm keyword. This example also
shows the risks of using inline assembler.
bool flag;
void Func()
{
while (!flag)
{
asm("IN R0, PIND \n"
"STS flag, R0");
}
}
Note: Because using symbols from inside the inline assembler code is not properly
visible to all parts of the compiler, you must use #pragma required when you
reference an external or module-local symbol only from inline assembler code. If you
do not, you can get an undefined symbol error when compiling. See required, page 334.
151
AFE1_AFE2-1:1
Calling assembler routines from C
Additionally, in this example, the assignment to the global variable flag is not noticed
by the compiler, which means the surrounding code cannot be expected to rely on the
inline assembler statement.
The inline assembler instruction will simply be inserted at the given location in the
program flow. The consequences or side-effects 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.
Inline assembler sequences have no well-defined interface with the surrounding code
generated from your C or C++ code. This makes the inline assembler code fragile, and
might also become a maintenance problem if you upgrade the compiler in the future.
There are also several limitations to using inline assembler:
● The compiler’s various optimizations will disregard any effects of the inline
sequences, which will not be optimized at all
● In general, assembler directives will cause errors or have no meaning. Data
definition directives will however work as expected
● Auto variables cannot be accessed.
Inline assembler is therefore often best avoided. If no suitable intrinsic function is
available, we recommend that you use modules written in assembler language instead
of inline assembler, because the function call to an assembler routine normally causes
less performance reduction.
One way of fulfilling these requirements is to create skeleton code in C, compile it, and
study the assembler list file.
AFE1_AFE2-1:1
Assembler language interface
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
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
153
AFE1_AFE2-1:1
Calling assembler routines from C++
named in the same way as the C or C++ module (skeleton), but with the filename
extension s90. 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.s90.
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, choose Project>Options>C/C++ Compiler>List and deselect the
suboption Include call frame information.
On the command line, use the option -lB instead of -lA. Note that CFI information
must be included in the source code to make the C-SPY Call Stack window work.
AFE1_AFE2-1:1
Assembler language interface
However, when using C linkage, the calling convention conforms to the C calling
convention. An assembler routine can therefore be called from C++ when declared in
this manner:
extern "C"
{
int MyRoutine(int);
}
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
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,
155
AFE1_AFE2-1:1
Calling convention
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—one old, which is used in version 1.x
of the compiler, and one new which is the default. 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
● Function entrance
● Function exit
● Return address handling
At the end of the section, some examples are shown to describe the calling convention
in practice.
For details about the --version1_calls option and the __version1 attribute, see
--version1_calls, page 276 and __version_1, page 315, respectively.
In the IDE, choose Use ICCA90 1.x calling convention on the Project>C/C++
Compiler>Code page.
AFE1_AFE2-1:1
Assembler language interface
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.
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.
157
AFE1_AFE2-1:1
Calling convention
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.
For both calling conventions, these 14 registers can be used as scratch registers by a
function:
R0-R3, R16-R23, and R30-R31
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.
For both calling conventions, these registers are preserved registers:
R4-R15 and R24-R27
Note that the registers R4-R15 can be locked from the command line and used for global
register variables; see --lock_regs, page 258 and __regvar, page 312.
AFE1_AFE2-1:1
Assembler language interface
Special registers
For some registers, you must consider certain prerequisites:
● The stack pointer—register Y—must at all times point to the last element on the
stack. In the eventuality of an interrupt, everything below the point the stack pointer
points to, will be destroyed.
● If using the -v4 or -v6 processor option, the RAMPY register is part of the data stack
pointer.
● If using a processor option which uses any of the registers EIND, RAMPX, or RAMPZ,
these registers are treated as scratch registers.
FUNCTION ENTRANCE
During a function call, the calling function:
● passes the parameters, either in registers or on the stack
● pushes any other parameters on the data stack (CSTACK)
Control is then passed to the called function with the return address being automatically
pushed on the return address stack (RSTACK).
The called function:
● stores any local registers required by the function on the data stack
● allocates space for its auto variables and temporary values
● proceeds to run the function itself.
Hidden parameters
In addition to the parameters visible in a function declaration and definition, there can
be hidden parameters:
● A function returning structures or unions larger than 4 bytes gets an extra hidden
parameter, which is a default pointer—depending on the used memory model—
pointing to the location where the result should be stored. This pointer must be
returned to the callee.
159
AFE1_AFE2-1:1
Calling convention
● For non-static C++ member functions, the this pointer is passed as the first
parameter (but placed after the return structure pointer, if there is one). Note that
static member functions do not have a this pointer.
Register parameters
For both calling conventions, the registers available for passing parameters are:
R16–R23
This would result in a being allocated to R16 (first fit), b to R19:R18 (alignment), c to
R23:R22:R21:R20 (first fit), and d to R17 (first fit).
AFE1_AFE2-1:1
Assembler language interface
A third example:
void baz(char a, char __far * b, int c, int d)
* Where b denotes an 8-bit data type, w denotes a 16-bit data type, and l denotes a 32-bit
data type. If the first and/or second parameter is a 3-byte pointer, it will be passed in
R16–R19 or R20–R22 respectively.
161
AFE1_AFE2-1:1
Calling convention
Saved registers
Auto variables
Temporary storage
Low
address Y
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.
AFE1_AFE2-1:1
Assembler language interface
Note that the size of a returned pointer depends on the memory model in use;
appropriate registers are used accordingly.
Interrupt functions
Interrupt functions differ from ordinary C functions in that:
● If used, flags and scratch registers are saved
● Calls to interrupt functions are made via interrupt vectors; direct calls are not
allowed
● No arguments can be passed to an interrupt function
● Interrupt functions return by using the RETI function.
For more information about interrupt functions, see Interrupt functions, page 64.
Monitor functions
A monitor function causes interrupts to be disabled during execution of the function. At
function entry, the status register SREG is saved and global interrupts are disabled. At
function exit, the global interrupt enable bit (I) is restored in the SREG register, and
thereby the interrupt status existing before the function call is also restored.
For more information about monitor functions, see Monitor functions, page 65.
EXAMPLES
The following section shows a series of declaration examples and the corresponding
calling conventions. The complexity of the examples increases toward the end.
163
AFE1_AFE2-1:1
Calling convention
Example 1
Assume this function declaration:
int add1(int);
This function takes one parameter in the register R17:R16, and the return value is passed
back to its caller in the register R17:R16.
This assembler routine is compatible with the declaration; it will return a value that is
one number higher than the value of its parameter:
subi R16,FF
sbci R17,FF
ret
Example 2
This example shows how structures are passed on the stack. Assume these declarations:
struct MyStruct
{
long long mA;
long long mB;
};
The calling function must reserve 16 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
R17:R16. The return value is passed back to its caller in the register R17:R16.
Example 3
The function below will return a structure of type struct MyStruct.
struct MyStruct
{
long long mA;
long long mB;
};
It is the responsibility of the calling function to allocate a memory location for the return
value 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 the first suitable register/register
pair, which is R16, R17:R16, and R18:R17:R16 for the Tiny, Small, Large, and Huge
memory model, respectively. The parameter x is passed in R19:R18, R19:R18, and
R21:R20 for the Tiny, Small, Large, and Huge memory model, respectively.
AFE1_AFE2-1:1
Assembler language interface
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 scalar, so there is no hidden parameter. The parameter
x is passed in R17:R16, and the return value is returned in R16, R17:R16, and
R18:R17:R16 for the Tiny, Small, and Large memory model, respectively.
FUNCTION DIRECTIVES
Note: This type of directive is primarily intended to support static overlay, a feature
which is useful in some smaller microcontrollers. The IAR C/C++ Compiler for AVR
does not use static overlay, because it has no use for it.
The function directives FUNCTION, ARGFRAME, LOCFRAME, and FUNCALL are generated
by the compiler to pass information about functions and function calls to the IAR
XLINK Linker. These directives can be seen if you use the compiler option Assembler
file (-lA) to create an assembler list file.
For more information about the function directives, see the IAR Assembler User Guide
for AVR.
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.
165
AFE1_AFE2-1:1
Call frame information
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.
For AVR, the defined resources depend on which processor option you are using. You
can find the resources in the list file section CFI Names.
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
Using C
● C language overview
● Extensions overview
C language overview
The IAR C/C++ Compiler for AVR 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
167
AFE1_AFE2-1:1
Extensions overview
● Inline assembler using the asm or the __asm keyword, see Inline assembler, page
151.
Note: Even though it is a C99 feature, the IAR C/C++ Compiler for AVR 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 169. 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 very 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
AFE1_AFE2-1:1
Using C
assembler, page 149. 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 363. For information
about AVR-specific library functions, see AVR-specific library functions, page 370.
Note: Any use of these extensions, except for the pragma directives, makes your source
code inconsistent with Standard C.
169
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.
Example
In this example, the type of the __segment_begin operator is void __near *.
#pragma segment="MYSEGMENT" __near
...
segment_start_address = __segment_begin("MYSEGMENT");
171
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 289.
● 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.
Assignment of a string constant to a pointer to any kind of character is allowed, and
no warning is issued.
AFE1_AFE2-1:1
Using C
173
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 250.
● 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.
175
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.
177
AFE1_AFE2-1:1
EC++ feature descriptions
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 __far C
{
public:
void MyF(); // Has a this pointer of type C __far *
void MyF() const; // Has a this pointer of type
// C __far const *
C(); // Has a this pointer pointing into far
// memory
C(C const &); // Takes a parameter of type C __far
// const & (also true of generated copy
// constructor)
int mI;
};
void MyH()
{
C cd; // Resides on the stack
}
Note: To place the C class in huge memory is not allowed, unless using the huge
memory model, because a huge pointer cannot be implicitly converted into a __far
pointer.
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 __far 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 __far.
179
AFE1_AFE2-1:1
EC++ feature descriptions
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.
class __far D : public C
{ // OK, same class memory
public:
void MyG();
int mJ;
};
class F : public C
{ // OK, will be associated with same class memory as C
public:
void MyG();
int mJ;
};
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.
181
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.
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 176.
183
AFE1_AFE2-1:1
EEC++ feature description
Example
// We assume that __far 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 __far is the memory type of the default
// pointer.
template<typename T> void fun(T *);
void MyF()
{
fun((int __near *) 0); // T = int. The result is different
// than the analogous situation with
// class template specializations.
fun((int *) 0); // T = int
fun((int __far *) 0); // T = int
fun((int __huge *) 0); // T = int __huge
}
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 __far is the memory type of the default
// pointer.
#pragma basic_template_matching
template<typename T> void fun(T *);
void MyF()
{
fun((int __near *) 0); // T = int __near
}
185
AFE1_AFE2-1:1
EEC++ feature description
Example
extern int __near X;
void Bar()
{
Foo<X>();
}
The containers in the STL, like vector and map, are memory attribute aware. This
means that a container can be declared to reside in a specific memory type which has the
following consequences:
● The container itself will reside in the chosen memory
● Allocations of elements in the container will use a heap for the chosen memory
● All references inside it use pointers to the chosen memory.
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.
AFE1_AFE2-1:1
Using C++
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 __near> X;
vector<int __huge> Y;
void MyF()
{
// The templated assign member method will work
X.assign(Y.begin(), Y.end());
Y.assign(X.begin(), X.end());
}
Example
#include <vector>
187
AFE1_AFE2-1:1
EEC++ feature description
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 __near> X;
vector<int __far> Y;
void MyF()
{
// The templated assign member method will work
X.assign(Y.begin(), Y.end());
Y.assign(X.begin(), X.end());
}
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.
AFE1_AFE2-1:1
Using C++
You must make sure that identifiers in your application do not interfere with identifiers
in the runtime library.
189
AFE1_AFE2-1:1
C++ language extensions
● 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
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.
};
AFE1_AFE2-1:1
Using C++
● 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.
191
AFE1_AFE2-1:1
C++ language extensions
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.
AVAILABLE STACKS
The compiler uses the internal data stack, CSTACK, for a variety of user program
operations. In addition, there is a specific stack for return addresses, RSTACK.
193
AFE1_AFE2-1:1
Heap considerations
Allocating a memory area for the stack is done differently using the command line
interface compared to when using the IDE.
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
● Allocating the heap size, see Setting up heap memory, page 92.
If you use any of the standard functions without a prefix, the function will be mapped to
the default memory type near.
Each heap will reside in a segment with the name _HEAP prefixed by a memory attribute,
for example NEAR_HEAP.
For information about available heaps, see Dynamic memory on the heap, page 61.
AFE1_AFE2-1:1
Application-related considerations
195
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
197
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
● 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.
Note that 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 provides
support for also controlling alignment, complement, bit order, and checksum unit size.
AFE1_AFE2-1:1
Application-related considerations
2 When configuring the linker to calculate a checksum, there are some basic choices to
make:
● Checksum algorithm
Choose which checksum algorithm you want to use. In this example, the CRC16
algorithm is used.
● Memory range
Using the IDE, the checksum will by default be calculated for all placement
directives (specified in the linker configuration file) for ROM-based memory. From
the command line, you can specify any ranges.
● Fill pattern
Specify a fill pattern—typically 0xFF or 0x00—for bytes with unknown values. The
fill pattern will be used in all checksum ranges.
For more information, see Briefly about checksum calculation, page 197.
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
199
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
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
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 avr\src\linker
directory of your product installation.
201
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
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. 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
During execution, the checksum calculated by the linker and the checksum calculated
by your application should be identical.
203
AFE1_AFE2-1:1
Checksum calculation for verifying image integrity
AFE1_AFE2-1:1
Efficient coding for
embedded applications
● Selecting data types
205
AFE1_AFE2-1:1
Selecting data types
String literals cannot be put in flash automatically, but you can use a local static variable
instead:
#include <pgmspace.h>
void f (int i)
{
static __flash char sl[] = "%d cookies\n";
printf_P(sl, i);
}
This does not result in more code compared to allowing string literals in flash.
To use flash strings, you must use alternative library routines that expect flash strings.
A few such alternative functions are provided— they are declared in the pgmspace.h
header file. They are flash alternatives for some common C library functions with an
extension _P. For your own code, you can always use the __flash keyword when
passing the strings between functions.
For reference information about the alternative functions, see AVR-specific library
functions, page 370.
AFE1_AFE2-1:1
Efficient coding for embedded applications
For information about representation of supported data types, pointers, and structures
types, see the chapter Data representation.
FLOATING-POINT TYPES
Using floating-point types on a microprocessor without a math coprocessor is very
inefficient, both in terms of code size and execution speed. Thus, 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.
However, the 64-bit format double supports higher precision and larger numbers.
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
--64bit_doubles compiler option (Use 64-bit doubles).
Unless the application requires the extra precision that 64-bit floating-point numbers
give, we recommend using 32-bit floating-point numbers instead.
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 285.
207
AFE1_AFE2-1:1
Selecting data types
● An application where some global variables are accessed from a large number of
locations. In this case they can be declared to be placed in memory with a smaller
pointer type
● An application where all data, with the exception of one large chunk of data, fits
into the region of one of the smaller memory types
● Data that must be placed at a specific memory location.
The IAR C/C++ Compiler for AVR provides memory attributes for placing data objects
in the different memory spaces, and for the DATA and CODE space (flash) there are
different memory attributes for placing data objects in different memory types, see
Using data memory attributes, page 54.
Efficient usage of memory type attributes can significantly reduce the application size.
For details about the memory types, see Memory types, page 54.
Use the -e compiler option to enable language extensions. See -e, page 250, for
additional information.
AFE1_AFE2-1:1
Efficient coding for embedded applications
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;
}
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;
};
} @ 40;
This declares an I/O register byte IOPORT at address 40. The I/O register has 2 bits
declared, way and out. Note that both the inner structure and the outer union are
anonymous.
209
AFE1_AFE2-1:1
Controlling data and function placement in memory
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.
Note: All declarations of __no_init 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.
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 @ 0xFF2000;/* 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. Both objects are placed in ROM.
This is useful for configuration parameters, which are accessible from an external
interface. Note that in the second case, the compiler is not obliged to actually read from
the variable, because the value is known.
#pragma location=0xFF2002
__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 @ 0xFF2006; /* Error, neither */
/* "__no_init" nor "const".*/
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++ */
211
AFE1_AFE2-1:1
Controlling data and function placement in memory
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
it is located in the default memory. Note that you must as always ensure that the segment
is placed in the appropriate memory area when linking.
__no_init int alpha @ "MY_NOINIT"; /* OK */
#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
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 usual, 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.
__near __no_init int alpha @ "MY_NEAR_NOINIT";/* Placed in
near*/
#pragma location="MY_FUNCTIONS"
void h(void);
Specify a memory attribute to direct the function to a specific memory, and then modify
the segment placement in the linker configuration file accordingly:
__nearfunc void f(void) @ "MY_NEARFUNC_FUNCTIONS";
213
AFE1_AFE2-1:1
Controlling compiler optimizations
AFE1_AFE2-1:1
Efficient coding for embedded applications
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
Low Same as above but variables only live for as long as they are
needed, not necessarily through their entire scope
Dead code elimination
Redundant label elimination
Redundant branch elimination
Medium Same as above, and:
Live-dead analysis and optimization
Code hoisting
Register content analysis and optimization
Common subexpression elimination
Static clustering
High (Balanced) Same as above, and:
Peephole optimization
Cross jumping
Cross call (when optimizing for size)
Function inlining
Code motion
Type-based alias analysis
Table 25: Compiler optimization levels
Note: Some of the performed optimizations can be individually enabled or disabled. For
more information about these, see Fine-tuning enabled transformations, page 216.
A high level of optimization might result in increased compile time, and will most likely
also 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.
215
AFE1_AFE2-1:1
Controlling compiler optimizations
speed, whereas size will trade speed for size. Note that one optimization sometimes
enables other optimizations to be performed, and an application might in some cases
become smaller even when optimizing for speed rather than size.
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 265 and optimize, page
332). 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.
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 259) 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.
AFE1_AFE2-1:1
Efficient coding for embedded applications
Note: This option has no effect at optimization levels None and Low.
For more information about the command line option, see --no_cse, page 261.
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 67.
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 261.
217
AFE1_AFE2-1:1
Facilitating good code generation
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. Thus, 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.
Static clustering
When static clustering is enabled, static and global variables that are defined within the
same module are arranged so that variables that are accessed in the same function are
stored close to each other. This makes it possible for the compiler to use the same base
pointer for several accesses.
Note: This option has no effect at optimization levels None and Low.
For more information about the command line option, see --no_clustering, page 260.
Cross call
Common code sequences are extracted to local subroutines. This optimization, which is
performed at optimization level High size, can reduce code size, sometimes
dramatically, on behalf of execution time and stack size. The resulting code might
however be difficult to debug. This optimization cannot be disabled using the #pragma
optimize directive.
If you want to use cross calls at any other optimization level, use --do_cross_call.
For more information about related command line options, see --no_cross_call, page
261, --do_cross_call, page 250, and --cross_call_passes, page 242.
AFE1_AFE2-1:1
Efficient coding for embedded applications
219
AFE1_AFE2-1:1
Facilitating good code generation
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 */
AFE1_AFE2-1:1
Efficient coding for embedded applications
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, so it cannot
be larger than 255. It also cannot be negative, which means that the integral promoted
value can never have the topmost 8 bits set.
221
AFE1_AFE2-1:1
Facilitating good code generation
By including the appropriate include file in your code, it is possible to access either the
whole register or any individual bit (or bitfields) from C code as follows:
/* whole register access */
PORTE = 0x12;
/* Bitfield accesses */
PORTE_Bit0 = 1;
You can also use the header files as templates when you create new header files for other
AVR devices.
AFE1_AFE2-1:1
Efficient coding for embedded applications
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.
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 311. Note that to use this keyword, language
extensions must be enabled; see -e, page 250. For more information, see also
object_attribute, page 332.
223
AFE1_AFE2-1:1
Facilitating good code generation
AFE1_AFE2-1:1
Part 2. Reference
information
This part of the IAR C/C++ Compiler User Guide for AVR contains these
chapters:
● Compiler options
● Data representation
● Extended keywords
● Pragma directives
● Intrinsic functions
● The preprocessor
● Segment reference
225
226
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 AVR 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:
iccavr 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.
227
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 iccavr command, either before
or after the source filename; see Invocation syntax, page 227.
● Via environment variables
The compiler automatically appends the value of the environment variables to every
command line; see Environment variables, page 228.
● Via a text file, using the -f option; see -f, page 254.
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:\program files\iar systems\embedded
workbench 7.n\avr\inc;c:\headers
QCCAVR Specifies command line options; for example: QCCAVR=-lA
asm.lst
Table 26: Compiler environment variables
AFE1_AFE2-1:1
External interface details
● 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:
iccavr ..\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 351.
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 r90.
229
AFE1_AFE2-1:1
Compiler output
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:
filename,linenumber level[tag]: message
filename The name of the source file in which the issue was encountered
linenumber The line number at which the compiler detected the issue
level The level of seriousness of the issue
tag A unique tag that identifies the diagnostic message
message An explanation, possibly several lines long
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.
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 269.
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 265.
231
AFE1_AFE2-1:1
Diagnostics
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 that is produced when the compiler finds a condition that not only
prevents code generation, but which 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
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 228.
233
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 (=), for example:
--misrac2004=n
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:
iccavr 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:
iccavr 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:
iccavr 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:
iccavr 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
235
AFE1_AFE2-1:1
Summary of compiler options
AFE1_AFE2-1:1
Compiler options
237
AFE1_AFE2-1:1
Summary of compiler options
AFE1_AFE2-1:1
Compiler options
239
AFE1_AFE2-1:1
Descriptions of compiler options
--64bit_doubles
Syntax --64bit_doubles
Description Use this option to force the compiler to use 64-bit doubles instead of 32-bit doubles
which is the default.
--64k_flash
Syntax --64k_flash
Description This option tells the compiler that the intended target processor does not have more than
64 Kbytes program flash memory (small flash), and that the AVR core therefore does
not have the RAMPZ register or the ELPM instruction.
This option can only be used together with the -v2, -v3, and -v4 processor options.
Project>Options>General Options>Target (No RAMPZ register)
--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.
AFE1_AFE2-1:1
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.
Note: The CLIB library is used by default. To use the DLIB library, use the --dlib or
the --dlib_config option instead.
241
AFE1_AFE2-1:1
Descriptions of compiler options
--cpu
Syntax --cpu=processor
Parameters
processor Specifies a specific device
Description The compiler supports different processor variants. Use this option to select a specific
processor variant for which the code will be generated.
Note that to specify the processor, you can use either the --cpu option or the -v option.
The --cpu option is, however, more precise because it contains more information about
the intended target than the more generic -v option.
--cross_call_passes
Syntax --cross_call_passes=N
Parameters
N The number of times to run the cross call optimizer, which can be
1–5.
Description Use this option to run the cross-call optimizer for decreasing the RSTACK usage. The
default is to run it until no more improvements can be made.
Note: Use this option if you have a target processor with a hardware stack or a small
internal return stack segment, RSTACK.
AFE1_AFE2-1:1
Compiler options
-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.
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
--debug, -r
Syntax --debug
-r
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
243
AFE1_AFE2-1:1
Descriptions of compiler options
--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 234.
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.r90: c:\iar\product\include\stdio.h
foo.r90: d:\myproject\include\foo.h
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.
AFE1_AFE2-1:1
Compiler options
--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.
Project>Options>C/C++ Compiler>Diagnostics>Treat these as remarks
245
AFE1_AFE2-1:1
Descriptions of 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 234.
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.
AFE1_AFE2-1:1
Compiler options
--disable_all_program_memory_load_instructions
Syntax --disable_all_program_memory_load_instructions
--disable_direct_mode
Syntax --disable_direct_mode
Description Use this option to prevent the compiler from generating the direct addressing mode
instructions LDS and STS.
To set this option, use: Project>Options>C/C++ Compiler>Extra Options.
--disable_library_knowledge
Syntax --disable_library_knowledge
Description Use this option to disable the knowledge about the support routines in the library.
To set this option, use: Project>Options>C/C++ Compiler>Extra Options.
--disable_mul
Syntax --disable_mul
247
AFE1_AFE2-1:1
Descriptions of compiler options
--disable_spm
Syntax --disable_spm
--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 259 and Multi-file compilation units, page 214.
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 249, --no_system_include, page 263, --system_include_dir, page
274, and --clib, page 241.
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 234.
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 and the library configuration files in the directory
avr\lib. For examples and information about prebuilt runtime libraries, see Prebuilt
runtime libraries, page 111.
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 108.
Note: This option only applies to the IAR DLIB runtime environment.
To set related options, choose:
Project>Options>General Options>Library Configuration
249
AFE1_AFE2-1:1
Descriptions of compiler options
--do_cross_call
Syntax --do_cross_call
Description Use this option to force the compiler to run the cross call optimizer, regardless of the
optimization level. The cross call optimizer is otherwise only run at high size
optimization.
-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++.
--eecr_address
Syntax --eecr_address address
Parameters
address The value of the EECR address. The default is 0x1C.
Description If you use the -v processor option, the --eecr_address option can be used for
modifying the value of the EECR address.
If you use the --cpu processor option, the --eecr_address option is implicitly set,
which means you should not use these options together.
--eeprom_size
Syntax --eeprom_size=N
Parameters
N The size of the EEPROM in bytes, 0–65536.
251
AFE1_AFE2-1:1
Descriptions of compiler options
Description Use this option to enable the __eeprom extended keyword by specifying the size of the
built-in EEPROM.
To use the __eeprom extended keyword, language extensions must be enabled.
See also Function storage, page 63, -e, page 250 and language, page 330.
To set related options, choose:
Project>Options>C/C++ Compiler>Code
--enable_external_bus
Syntax --enable_external_bus
Description Use this option to make the compiler add the special __require statement which
makes XLINK include the code in startup.s90 that enables the external data bus. Use
this option if you intend to place RSTACK in external RAM.
Note: The code in cstartup.s90 that enables the external data bus is preferably
placed in low_level_init instead.
--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
AFE1_AFE2-1:1
Compiler options
--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
--enhanced_core
Syntax --enhanced_core
Description Use this option to allow the compiler to generate instructions from the enhanced
instruction set that is available in some AVR devices, for example ATmega161.
The enhanced instruction set consists of these instructions:
MUL
MOVW
MULS
MULSU
FMUL
FMULS
FMULSU
LPM Rd,Z
LPM Rd,Z+
ELPM Rd,Z
ELPM Rd,Z+
SPM
--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.
253
AFE1_AFE2-1:1
Descriptions of compiler options
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 234.
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.
--force_switch_type
Syntax --force_switch_type={0|1|2}
Parameters
0 Library call with switch table
1 Inline code with switch table
2 Inline compare/jump logic
AFE1_AFE2-1:1
Compiler 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.
--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.
-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.
255
AFE1_AFE2-1:1
Descriptions of compiler options
--initializers_in_flash
Syntax --initializers_in_flash
Description Use this option to place aggregate initializers in flash memory. These initializers are
otherwise placed in the external segments _C or in the flash segments _F if the compiler
option -y was also specified.
An aggregate initializer—an array or a struct—is constant data that is copied to the stack
dynamically at runtime, in this case every time a function is entered.
The drawback of placing data in flash memory is that it takes more time to copy it; the
advantage is that it does not occupy memory in the data space.
Local variables with aggregate initializers are copied from the segments:
Data Default -y --initializers_in_flash
auto aggregates NEAR_C NEAR_F NEAR_F
Table 29: Accessing variables with aggregate initializers
See also -y, page 279 and Initialization of local aggregates at function invocation, page 77.
To set related options, choose:
Project>Options>C/C++ Compiler>Code
-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 *
AFE1_AFE2-1:1
Compiler options
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
* 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 234.
Description Use this option to generate an assembler or C/C++ listing to a file. Note that this option
can be used one or more times on the command line.
To set related options, choose:
Project>Options>C/C++ Compiler>List
--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
257
AFE1_AFE2-1:1
Descriptions of compiler options
--lock_regs
Syntax --lock_regs N
Parameters
N The number of registers to lock, 0–12.
Description Use this option to lock registers that are to be used for global register variables. When
you use this option, the registers R15 and downwards will be locked.
To maintain module consistency, make sure to lock the same number of registers in all
modules.
Note: Locking more than nine registers might cause linking to fail. Because the
pre-built libraries delivered with the product do not lock any registers, a library function
might potentially use any of the lockable registers. Any such resource conflict between
locked registers and compiler-used registers will be reported at link time.
If you need to lock any registers in your code, the library must therefore be rebuilt with
the same set of locked registers.
To set related options, choose:
Project>Options>C/C++ Compiler>Code
--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.
--memory_model, -m
Syntax --memory_model={tiny|t|small|s|large|l|huge|h}
-m{tiny|t|small|s|large|l<huge|h}
Parameters
tiny, t Specifies the Tiny memory model
small, s Specifies the Small memory model
AFE1_AFE2-1:1
Compiler options
Description Use this option to specify the memory model, for which the code is to be generated.
By default, the compiler generates code for the Tiny memory model for all processor
options except -v4 and -v6 where the Small memory model is the default.
Use the -m or the --memory_model option if you want to generate code for a different
memory model.
Example To generate code for the Large memory model, give the command:
iccavr filename -ml
or:
iccavr filename --memory_model=large
--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 248, --output, -o, page 267, and Multi-file compilation
units, page 214.
Project>Options>C/C++ Compiler>Multi-file compilation
259
AFE1_AFE2-1:1
Descriptions of 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
--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_clustering
Syntax --no_clustering
AFE1_AFE2-1:1
Compiler options
--no_code_motion
Syntax --no_code_motion
--no_cross_call
Syntax --no_cross_call
This optimization is performed at size optimization, level High. Note that, although the
optimization can drastically reduce the code size, this optimization increases the
execution time.
--no_cse
Syntax --no_cse
261
AFE1_AFE2-1:1
Descriptions of 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_rampd
Syntax --no_rampd
Description Use this option to make the compiler use the RAMPZ register instead of RAMPD. This
option corresponds to the instructions LDS and STS.
Note that this option is only useful on processor variants with more than 64 Kbytes data
(-v4 and -v6).
To set this option, use Project>Options>C/C++ Compiler>Extra 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.
AFE1_AFE2-1:1
Compiler options
--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 248, --dlib_config, page 249, and --system_include_dir, page 274.
Project>Options>C/C++ Compiler>Preprocessor>Ignore standard include
directories
--no_tbaa
Syntax --no_tbaa
263
AFE1_AFE2-1:1
Descriptions of compiler options
Project>Options>C/C++ Compiler>Optimizations>Enable
transformations>Type-based alias analysis
--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.
--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.
AFE1_AFE2-1:1
Compiler 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.
-O
Syntax -O[n|l|m|h|hs|hz]
Parameters
n None* (Best debug support)
l (default) Low*
m Medium
h High, balanced
265
AFE1_AFE2-1:1
Descriptions of compiler options
*The most important difference between None and Low is that at 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 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.
--only_stdout
Syntax --only_stdout
Description Use this option to make the compiler use the standard output stream (stdout) also for
messages that are normally directed to the error output stream (stderr).
This option is not available in the IDE.
AFE1_AFE2-1:1
Compiler options
--output, -o
Syntax --output {filename|directory}
-o {filename|directory}
Parameters See Rules for specifying a filename or directory as parameters, page 234.
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 r90. 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
--predef_macros
Syntax --predef_macros {filename|directory}
Parameters See Rules for specifying a filename or directory as parameters, page 234.
Description Use this option to list the predefined symbols. 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 that this option requires that you specify a source file on the command line.
267
AFE1_AFE2-1:1
Descriptions of compiler options
--preinclude
Syntax --preinclude includefile
Parameters See Rules for specifying a filename or directory as parameters, page 234.
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 234.
--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
AFE1_AFE2-1:1
Compiler options
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.
--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 that 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
--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
269
AFE1_AFE2-1:1
Descriptions of compiler options
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
--root_variables
Syntax --root_variables
Description Use this option to apply the __root extended keyword to all global and static variables.
This will make sure that the variables are not removed by the IAR XLINK Linker.
Note: The --root_variables option is always available, even if you do not specify
the compiler option -e, language extensions.
To set related options, choose:
Project>Options>C/C++ Compiler>Code>Force generation of all global and static
variables
AFE1_AFE2-1:1
Compiler options
-s
Syntax -s[2|3|6|9]
Parameters
2 None* (Best debug support)
3 (default) Low*
6 Medium
*The most important difference between -s2 and -s3 is that at level 2, all non-static
variables will live during their entire scope.
Description Use this option to make the compiler optimize the code for maximum execution speed.
If no optimization option is specified, the optimization level 3 is used by default.
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.
Note: The -s and -z options cannot be used at the same time.
Note: This option is available for backward compatibility. Use -O instead.
--segment
Syntax --segment __memory_attribute=NEWSEGMENTNAME
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 all functions or data objects declared with the __memory_attribute in
segments with names that begin with NEWSEGMENTNAME.
● To change the name of the segments SWITCH, INITTAB, CSTACK, RSTACK, and
INTVEC to a different 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
271
AFE1_AFE2-1:1
Descriptions of compiler options
that any changes to the segment names require corresponding modifications in the linker
configuration file.
Example This command places the __near int a; defined variable in the MYDATA_Z segment:
--segment __near=MYDATA
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 210 and Summary of extended
keywords, page 299.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
--separate_cluster_for_initialized_variables
Syntax --separate_cluster_for_initialized_variables
Description Use this option to separate initialized and non-initialized variables when using variable
clustering. The option makes the *_ID segments smaller but can generate larger code.
To set this option, use Project>Options>C/C++ Compiler>Extra 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.
AFE1_AFE2-1:1
Compiler options
--spmcr_address
Syntax --spmcr_address address
Parameters
address The SPMCR address, where 0x37 is the default.
--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.
--string_literals_in_flash
Syntax --string_literals_in_flash
Description Use this option to put “string” in the __nearflash or __farflash segment depending
on the processor option.
When this option is used, library functions taking a string literal as a parameter will no
longer be type-compatible. Use the *_P library function variants (for example
printf_P).
273
AFE1_AFE2-1:1
Descriptions of compiler options
--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 234.
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.
--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.
AFE1_AFE2-1:1
Compiler options
-v
Syntax -v{0|1|2|3|4|5|6}
Parameters
0 (default) The code space is physically limited to 8 Kbytes, and the RCALL/RJMP
instructions are used for reaching the code space. Interrupt vectors are 2
bytes long. The compiler assumes that the index registers X, Y, and Z are
eight bits wide when accessing the built-in SRAM. It also assumes that
it is not possible to attach any external memory to the microcontroller
and that it therefore should not generate any constant segment in data
space (_C segment). Instead the compiler adds an implicit -y command
line option. It will also try to place all aggregate initializers in flash
memory, that is, the implicit --initializers_in_flash option is
also added to the command line. Relative function calls are made.
1 The code space is physically limited to 8 Kbytes, and the RCALL/RJMP
instructions are used for reaching the code space. Interrupt vectors are 2
bytes long. The compiler assumes that it is possible to have external
memory and will therefore generate _C segments. Relative function calls
are made.
2 The code space is physically limited to 128 Kbytes, and, if possible, the
RCALL/RJMP instructions are used for reaching the code space. If that is
not possible, CALL/JMP is used. Function calls through function pointers
use ICALL/IJMP. 2 bytes are used for all function pointers. Interrupt
vectors are 4 bytes long. The compiler assumes that the index registers
X, Y, and Z are eight bits wide when accessing the built-in SRAM. It also
assumes that it is not possible to attach any external memory to the
microcontroller and that it should therefore not generate any constant
segment in data space (_C segment). Instead the compiler adds an
implicit -y command line option. It will also try to place all aggregate
initializers in flash memory, that is, the implicit
--initializers_in_flash option is also added to the command
line.
3 The code space is physically limited to 128 Kbytes, and, if possible, the
RCALL/RJMP instructions are used for reaching the code space. If that is
not possible, CALL/JMP is used. Function calls through function pointers
use ICALL/IJMP. Two bytes are used for all function pointers. Interrupt
vectors are four bytes long. The compiler assumes that it is possible to
have external memory and will therefore generate _C segments.
275
AFE1_AFE2-1:1
Descriptions of compiler options
4 The code space is physically limited to 128 Kbytes, and, if possible, the
RCALL/RJMP instructions are used for reaching the code space. If that is
not possible, CALL/JMP is used. Function calls through function pointers
use ICALL/IJMP. Two bytes are used for all function pointers. Interrupt
vectors are four bytes long. The compiler assumes that it is possible to
have external memory and will therefore generate _C segments.
5 Allows function calls through farfunc function pointers to cover the
entire 8 Mbyte code space by using EICALL/EIJMP. Three bytes are
used for function pointers. Interrupt vectors are four bytes long. The
compiler assumes that it is possible to have external memory and will
therefore generate _C segments.
6 Allows function calls through farfunc function pointers to cover the
entire 8 Mbyte code space by using EICALL/EIJMP. Three bytes are
used for function pointers. Interrupt vectors are four bytes long.The
compiler assumes that it is possible to have external memory and will
therefore generate _C segments.
Description Use this option to select the processor device for which the code is to be generated.
See also --cpu, page 242 and Processor configuration, page 49.
To set related options, choose:
Project>Options>General Options>Processor configuration
--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.
--version1_calls
Syntax --version1_calls
Description Use this option to make all functions and function calls use the calling convention of the
A90 IAR Compiler, ICCA90, which is described in Calling convention, page 155.
AFE1_AFE2-1:1
Compiler options
To change the calling convention of a single function, use the __version_1 function
type attribute. See __version_1, page 315 for detailed information.
Project>Options>C/C++ Compiler>Code>Use ICCA90 1.x calling convention
--version2_calls
Syntax --version2_calls
--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.
--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.
277
AFE1_AFE2-1:1
Descriptions of compiler options
--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.
--xmcra_address
Syntax --xmcra_address address
Parameters
address The address of XMCRA. The default is 0x74.
AFE1_AFE2-1:1
Compiler options
-y
Syntax -y
Description Use this option to override the default placement of constants and literals.
Without this option, constants and literals are placed in an external const segment,
segmentbasename_C. With this option, constants and literals will instead be placed in
the initialized segmentbasename_I data segments that are copied from the
segmentbasename_ID segments by the system startup code.
-z
Syntax -z[2|3|6|9]
Parameters
2 None* (Best debug support)
3 (default) Low*
6 Medium
*The most important difference between -z2 and -z3 is that at level 2, all non-static
variables will live during their entire scope.
Description Use this option to make the compiler optimize the code for minimum size. If no
optimization option is specified, the optimization level 3 is used by default.
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.
Note: The -s and -z options cannot be used at the same time.
Note: This option is available for backward compatibility. Use -O instead.
279
AFE1_AFE2-1:1
Descriptions of compiler options
--zero_register
Syntax --zero_register
Description Use this option to make the compiler use register R15 as zero register, which means that
register R15 is assumed to always contain zero.
This option can in some cases reduce the size of the generated code, especially in the
Large memory model. The option might be incompatible with the supplied runtime
libraries. The linker will issue a link-time error if any incompatibilities arise.
To set this option, use Project>Options>C/C++ Compiler>Extra Options.
AFE1_AFE2-1:1
Data representation
● Alignment
● Byte order
● Pointer types
● Structure types
● Type qualifiers
See the chapter Efficient coding for embedded applications for information about
which data types and pointers 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.
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
the structure.
281
AFE1_AFE2-1:1
Byte order
Note that with the #pragma data_alignment directive you can increase the
alignment demands on specific variables.
Byte order
The AVR microcontroller stores data in little-endian byte order.
In the little-endian byte order, the least significant byte is stored at the lowest address in
memory. The most significant byte is stored at the highest address.
In the big-endian byte order, the most significant byte is stored at the lowest address in
memory. The least significant byte is stored at the highest address. If you use the
big-endian byte order, it might be necessary to use the
#pragma bitfields=reversed directive to be compatible with code for other
compilers and I/O register definitions of some devices, see Bitfields, page 284.
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};
283
AFE1_AFE2-1:1
Basic data types—integer types
The wchar_t data type is supported by default in the C++ language. To use the
wchar_t type also in C source code, you must include the file stddef.h from the
runtime library.
Note: The IAR CLIB Library has only rudimentary support for wchar_t.
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.
In the IAR C/C++ Compiler for AVR, 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 321.
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.
AFE1_AFE2-1:1
Data representation
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.
This is the layout of bitfield_example:
Note: The size of double and long double depends on the --64bit_doubles
option, see --64bit_doubles, page 240. The type long double uses the same precision
as double.
285
AFE1_AFE2-1:1
Basic data types—floating-point types
FLOATING-POINT ENVIRONMENT
Exception flags are not supported. The feraiseexcept function does not raise any
exceptions.
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
● Not a number (NaN) is represented by setting the exponent to the highest positive
value and the mantissa to a non-zero value. The value of the sign bit is ignored.
● Subnormal numbers are used for representing values smaller than what can be
represented by normal values. The drawback is that the precision will decrease with
smaller values. The exponent is set to 0 to signify that the number is subnormal,
even though the number is treated as if the exponent was 1. Unlike normal numbers,
subnormal numbers do not have an implicit 1 as the most significant bit (the MSB)
of the mantissa. The value of a subnormal number is:
(-1)S * 2(1-BIAS) * 0.Mantissa
where BIAS is 127 and 1023 for 32-bit and 64-bit floating-point values, respectively.
Note: The IAR CLIB Library does not fully support the special cases of floating-point
numbers, such as infinity, NaN, and subnormal numbers. 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
The size of function pointers is always 16 or 24 bits, and they can address the entire
memory. The internal representation of a function pointer is the actual address it refers
to divided by two.
These function pointers are available:
Keyword Address range Pointer size Description
__nearfunc 0–0x1FFFE 16 bits Can be called from any part of the
code memory, but must reside in the
first 128 Kbytes of that space.
__farfunc 0–0x7FFFFE 24 bits No restrictions on code placement.
Table 32: Function pointers
DATA POINTERS
Data pointers have three sizes: 8, 16, or 24 bits. These data pointers are available:
Pointer
Keyword Memory space Index type Address range
size
__tiny 8 bits Data signed char 0x–0xFF
Table 33: Data pointers
287
AFE1_AFE2-1:1
Pointer types
Pointer
Keyword Memory space Index type Address range
size
__near 16 bits Data signed int 0x0–0xFFFF
__far 24 bits Data signed int 0x0–0xFFFFFF
(16-bit arithmetics)
__huge 24 bits Data signed long 0x0–0xFFFFFF
__tinyflash 8 bits Code signed char 0x0–0xFF
__flash 16 bits Code signed int 0x0–0xFFFF
__farflash 24 bits Code signed int 0x0–0xFFFFFF
(16-bit arithmetic)
__hugeflash 24 bits Code signed long 0x0–0xFFFFFF
__eeprom 8 bits EEPROM signed char 0x0–0xFF
__eeprom 16 bits EEPROM signed int 0x0–0xFFFF
__generic 16 bits Data/Code signed int The most significant bit
24 bits signed long (MSB) determines
whether __generic
points to CODE (1) or
DATA (0). The small
generic pointer is
generated for the
processor options -v0
and -v1.
Table 33: Data pointers (Continued)
AFE1_AFE2-1:1
Data representation
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 via casting to the largest
possible pointer that fits in the integer
● 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 gives an undefined result.
size_t
size_t is the unsigned integer type of the result of the sizeof operator. In the IAR
C/C++ Compiler for AVR, the type used for size_t depends on the processor option
used:
When using the Large or Huge memory model, the typedef for size_t is unsigned
long int.
Note that some data memory types might be able to accommodate larger, or only
smaller, objects than the memory pointed to by default pointers. In this case, the type of
the result of the sizeof operator could be a larger or smaller unsigned integer type.
There exists a corresponding size_t typedef for each memory type, named after the
memory type. In other words, __near_size_t for __near memory.
ptrdiff_t
ptrdiff_t is the signed integer type of the result of subtracting two pointers. This table
shows the typedef of ptrdiff_t depending on the processor option:
289
AFE1_AFE2-1:1
Structure types
Note that subtracting pointers other than default pointers could result in a smaller or
larger integer type. In each case, this integer type is the signed integer variant of the
corresponding size_t type.
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; /* Result: -5536 */
intptr_t
intptr_t is a signed integer type large enough to contain a void *. In the IAR C/C++
Compiler for AVR, the type used for intptr_t is long int when using the Large or
Huge memory model and int in all other cases.
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).
AFE1_AFE2-1:1
Data representation
struct First
{
char c;
short s;
} s;
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:
291
AFE1_AFE2-1:1
Type qualifiers
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 AVR are described
below.
For all combinations of object types not listed, only the rule that states that all accesses
are preserved applies.
AFE1_AFE2-1:1
Data representation
To store the object in read-only memory instead, but still make it possible to access it as
a const volatile object, follow this example:
/* Header */
extern int const xVar;
#define x (*(int const volatile *) &xVar)
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.
293
AFE1_AFE2-1:1
Data types in C++
AFE1_AFE2-1:1
Extended keywords
● General syntax rules for extended keywords
For information about the address ranges of the different memory areas, see
the chapter Segment reference.
Use the -e compiler option to enable language extensions. See -e, page 250.
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.
295
AFE1_AFE2-1:1
General syntax rules for extended keywords
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.
Memory attributes
A memory attribute corresponds to a certain logical or physical memory in the
microcontroller.
Available function memory attributes:
__nearfunc, __farfunc
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.
__near int i;
int __near j;
AFE1_AFE2-1:1
Extended keywords
In all cases, if a memory attribute is not specified, an appropriate default memory type
is used.
Using a type definition can sometimes make the code clearer:
typedef __near int d16_int;
d16_int *q1;
d16_int is a typedef for integers in near 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=__near
int * q2;
or
void (__interrupt my_handler)(void);
297
AFE1_AFE2-1:1
General syntax rules for extended keywords
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.
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, __ro_placement, __no_runtime_init
● Object attributes that can be used for functions and variables:
location, @, __root
● Object attributes that can be used for functions:
__intrinsic, __monitor, __nested, __noreturn, vector
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 210. For more information about vector, see vector, page
339.
AFE1_AFE2-1:1
Extended keywords
Note: Object attributes cannot be used in combination with the typedef keyword.
299
AFE1_AFE2-1:1
Descriptions of extended keywords
__eeprom
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __eeprom memory attribute overrides the default storage of variables given by the
selected memory model and places individual initialized and non-initialized variables in
the built-in EEPROM of the AVR microcontroller. These variables can be used like any
other variable and provide a convenient way to access the built-in EEPROM.
AFE1_AFE2-1:1
Extended keywords
You can also override the supplied support functions to make the __eeprom memory
attribute access an EEPROM or flash memory that is placed externally but not on the
normal data bus, for example on an I2C bus.
To do this, you must write a new EEPROM library routines file and include it in your
project. The new file must use the same interface as the eeprom.s90 file in the
avr\src\lib directory (visible register use, the same entry points and the same
semantics).
Variables declared __eeprom are initialized only when a downloadable linker output
file is downloaded to the system, and not every time the system startup code is executed.
You can also use the __eeprom attribute to create a pointer explicitly pointing to an
object located in the EEPROM memory.
__ext_io
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __ext_io memory attribute overrides the default storage of variables given by the
selected memory model and allows individual objects to be accessed by use of the
special I/O instructions in the AVR microcontroller. The __ext_io memory attribute
implies that the object is __no_init and volatile.
Your application may access the AVR I/O system by using the memory-mapped internal
special function registers (SFRs). To access the AVR I/O system efficiently, the
__ext_io memory attribute should be included in the code.
301
AFE1_AFE2-1:1
Descriptions of extended keywords
__far
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __far memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in far memory.
You can also use the __far attribute to create a pointer explicitly pointing to an object
located in the far memory.
__farflash
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __farflash memory attribute overrides the default storage of variables given by
the selected memory model and places individual variables and constants in flash (code)
memory. You can also use the __farflash attribute to create a pointer explicitly
pointing to an object located in the flash (code) memory.
Note: It is preferable to declare flash objects as const. The __farflash memory
attribute is only available for AVR chips with more than 64 Kbytes of flash memory.
AFE1_AFE2-1:1
Extended keywords
__farfunc
Syntax Follows the generic syntax rules for memory type attributes that can be used on
functions, see Type attributes, page 295.
Description The __farfunc memory attribute overrides the default storage of functions given by
the selected code model and places individual functions in code memory. You can also
use the __farfunc attribute to create a pointer explicitly pointing to a function located
in FARCODE memory (0-0xFFFFFF).
The default code pointer for the -v5 and -v6 processor options is __farfunc, and it
only affects the size of the function pointers.
Note that pointers with function memory attributes have restrictions in implicit and
explicit casts when casting between pointers and also when casting between pointers
and integer types.
It is possible to call a __nearfunc function from a __farfunc function and vice versa.
Only the size of the function pointer is affected.
__flash
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
303
AFE1_AFE2-1:1
Descriptions of extended keywords
Description The __flash memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in flash (code)
memory.
Note that it is preferable to declare flash objects as constant. The __flash keyword is
available for most AVR processors.
Because the AVR microcontrollers have only a small amount of on-board RAM, this
memory should not be wasted on data that could be stored in flash memory (of which
there is much more). However, because of the architecture of the processor, a default
pointer cannot access the flash memory. The __flash keyword is used to identify that
the constant should be stored in flash memory.
A header file called pgmspace.h is installed in the avr\inc directory, to provide some
standard C library functions for taking strings stored in flash memory as arguments.
You can also use the __flash attribute to create a pointer explicitly pointing to an
object located in the flash (code) memory.
Note: The __flash option cannot be used in a reduced ATtiny core.
Example A program defines a couple of strings that are stored in flash memory:
__flash char str1[] = "Message 1";
__flash char str2[] = "Message 2";
The program creates a __flash pointer to point to one of these strings, and assigns it
to str1:
char __flash *msg;
msg=str1;
Using the strcpy_P function declared in pgmspace.h, a string in flash memory can be
copied to another string in RAM as follows:
strcpy_P(dest, msg);
AFE1_AFE2-1:1
Extended keywords
__generic
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __generic pointer type attribute declares a generic pointer that can point to
objects in both code and data space. The size of the generic pointer depends on which
processor option is used.
The most significant bit (MSB) determines whether __generic points to Code
(MSB=1) or Data (MSB=0).
It is not possible to place objects in a generic memory area, only to point to it. When
using generic pointers, make sure that objects that have been declared __far and
__huge are located in the range 0x0–0x7FFFFF. Objects may still be placed in the
entire data address space, but a generic pointer cannot point to objects in the upper half
of the data address space.
The __generic keyword cannot be used with the #pragma type_attribute
directive for a pointer.
Access through a __generic pointer is implemented with inline code. Because this
type of access is slow and generates a lot of code, __generic pointers should be
avoided when possible.
__huge
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __huge memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in huge memory.
305
AFE1_AFE2-1:1
Descriptions of extended keywords
You can also use the __huge attribute to create a pointer explicitly pointing to an object
located in the huge memory.
__hugeflash
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __hugeflash memory attribute overrides the default storage of variables given by
the selected memory model and places individual variables and constants in flash (code)
memory. You can also use the __hugeflash attribute to create a pointer explicitly
pointing to an object located in the flash (code) memory.
Note that it is preferable to declare flash objects as constant. The __hugeflash
memory attribute is only available for AVR microcontrollers with at least 64 Kbytes of
flash memory.
AFE1_AFE2-1:1
Extended keywords
__interrupt
Syntax See Syntax for type attributes used on functions, page 297.
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 64, vector, page 339, and INTVEC, page 385.
__intrinsic
Description The __intrinsic keyword is reserved for compiler internal use only.
__io
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __io memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in I/O memory.
307
AFE1_AFE2-1:1
Descriptions of extended keywords
__monitor
Syntax See Syntax for object attributes, page 298.
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 65. For information about related intrinsic functions, see
__disable_interrupt, page 343, __enable_interrupt, page 343, __get_interrupt_state,
page 344, and __set_interrupt_state, page 348, respectively.
__near
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __near memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in near memory.
You can also use the __near attribute to create a pointer explicitly pointing to an object
located in the near memory.
__nearfunc
Syntax Follows the generic syntax rules for memory type attributes that can be used on
functions, see Type attributes, page 295.
AFE1_AFE2-1:1
Extended keywords
Description The __nearfunc memory attribute overrides the default storage of functions given by
the selected code model and places individual functions in near memory.
Functions declared __nearfunc can be called from the entire code memory area, but
must reside in the first 128 Kbytes of the code memory.
The default for the -v0 to -v4 processor options is __nearfunc, and it only affects the
size of the function pointers.
Note that pointers with function memory attributes have restrictions in implicit and
explicit casts when casting between pointers and also when casting between pointers
and integer types.
It is possible to call a __nearfunc function from a __farfunc function and vice versa.
Only the size of the function pointer is affected.
You can also use the __nearfunc attribute to create a pointer explicitly pointing to a
function located in CODE memory (0-0xFFFF).
__nested
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description Use the __nested keyword to implement a nested interrupt, in other words a new
interrupt can be served inside an interrupt function. A nested interrupt service routine
acts like a normal interrupt service routine except that it sets the interrupt enable bit
before any registers are saved.
309
AFE1_AFE2-1:1
Descriptions of extended keywords
__no_alloc, __no_alloc16
Syntax See Syntax for object attributes, page 298.
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.
__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.
AFE1_AFE2-1:1
Extended keywords
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 that there is no such runtime support in C-SPY, unless you
use an external plugin module.
__no_init
Syntax See Syntax for object attributes, page 298.
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_runtime_init
Syntax Follows the generic syntax rules for object attributes, see Object attributes, page 298.
Description The __no_runtime_init keyword is used for declaring initialized variables for which
the initialization is performed when programming the device. These variables are not
initialized at runtime during system startup.
Note: The __no_runtime_init keyword cannot be used in combination with the
typedef keyword.
311
AFE1_AFE2-1:1
Descriptions of extended keywords
__noreturn
Syntax See Syntax for object attributes, page 298.
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.
__raw
Syntax See Syntax for object attributes, page 298.
__regvar
Syntax Follows the generic syntax rules for type attributes that can be used on data, see Type
attributes, page 295.
Description The __regvar extended keyword is used for declaring that a global or static variable
should be placed permanently in the specified register or registers. The registers R4–R15
can be used for this purpose, provided that they have been locked with the
--lock_regs compiler option.
Note:
● An object declared __regvar cannot have an initial value.
● The__regvar option cannot be used in a reduced ATtiny core.
AFE1_AFE2-1:1
Extended keywords
This will create the 16-bit integer variable counter, which will always be available in
R15:R14. At least two registers must be locked.
See also --memory_model, -m, page 258, --lock_regs, page 258, and Preserved registers, page
158.
__root
Syntax See Syntax for object attributes, page 298.
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 298.
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.
In some cases (primarily involving simple constructors), the compiler will be able to
optimize C++ dynamic initialization of a data object into static initialization. In that case
no error message will be issued for the object.
313
AFE1_AFE2-1:1
Descriptions of extended keywords
__task
Syntax See Syntax for type attributes used on functions, page 297.
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.
__tiny
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __tiny memory attribute overrides the default storage of variables given by the
selected memory model and places individual variables and constants in tiny memory.
You can also use the __tiny attribute to create a pointer explicitly pointing to an object
located in the tiny memory.
AFE1_AFE2-1:1
Extended keywords
__tinyflash
Syntax Follows the generic syntax rules for memory type attributes that can be used on data
objects, see Type attributes, page 295.
Description The __tinyflash memory attribute overrides the default storage of variables given by
the selected memory model and places individual variables and constants in flash (code)
memory. You can also use the __tinyflash attribute to create a pointer explicitly
pointing to an object located in the flash (code) memory.
__version_1
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __version_1 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
A90 IAR C Compiler instead of the default calling convention. The __version_1
calling convention is preferred when calling assembler functions from C.
__version_2
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __version_2 keyword is available for backward compatibility of the interface for
calling assembler routines from C. The keyword makes a function use the
V2.10-V4.10B calling convention instead of the default calling convention.
315
AFE1_AFE2-1:1
Descriptions of extended keywords
__version_4
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
__x
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __x keyword places the first pointer of the parameter list in the register X. This
keyword is used by parts of the runtime library.
Note: This keyword can give very efficient code in a local perspective, but should be
used with care because it changes the calling convention and might have a negative
effect on the size of the entire application.
__x_z
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __x_z keyword places the first pointer of the parameter list in the register X and the
second one in register Z. This keyword is used by parts of the runtime library.
Note: This keyword can give very efficient code in a local perspective, but should be
used with care because it changes the calling convention and might have a negative
effect on the size of the entire application.
AFE1_AFE2-1:1
Extended keywords
__z
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __z keyword places the first pointer of the parameter list in the register Z. This
keyword is used by parts of the runtime library.
Note: This keyword can give very efficient code in a local perspective, but should be
used with care because it changes the calling convention and might have a negative
effect on the size of the entire application.
__z_x
Syntax Follows the generic syntax rules for type attributes that can be used on functions, see
Type attributes, page 295.
Description The __z_x keyword places the first pointer of the parameter list in the register Z and the
second one in register X. This keyword is used by parts of the runtime library.
Note: This keyword can give very efficient code in a local perspective, but should be
used with care because it changes the calling convention and might have a negative
effect on the size of the entire application.
317
AFE1_AFE2-1:1
Descriptions of extended keywords
AFE1_AFE2-1:1
Pragma directives
● Summary of pragma directives
319
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
407.
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 184.
void MyF()
{
fun((int __near *) 0); // T = int __near
}
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.
321
AFE1_AFE2-1:1
Descriptions of pragma directives
Description Use this pragma directive to control the order of bitfield members.
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
AFE1_AFE2-1:1
Pragma directives
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
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 Use this pragma directive to place 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.).
323
AFE1_AFE2-1:1
Descriptions of pragma directives
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.
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 thus be used for creating situations where the size is not a
multiple of the alignment.
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 Use this pragma directive to place 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...]
AFE1_AFE2-1:1
Pragma directives
@ segment_name
Parameters
type_attribute See Type attributes, page 295.
object_attribute See Object attributes, page 298.
@ segment_name See Data and function placement in segments, page 212.
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...]
325
AFE1_AFE2-1:1
Descriptions of pragma directives
Parameters
type_attribute See Type attributes, page 295.
object_attributes See Object attributes, page 298.
@ segment_name See Data and function placement in segments, page 212.
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
AFE1_AFE2-1:1
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.
327
AFE1_AFE2-1:1
Descriptions of 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.
AFE1_AFE2-1:1
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.
329
AFE1_AFE2-1:1
Descriptions of 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
AFE1_AFE2-1:1
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="FLASH"
#pragma location="FLASH"
__no_init char PORT1; /* PORT1 is located in segment FLASH */
Note: This still places the variables in DATA memory, and not in CODE.
See also Controlling data and function placement in memory, page 210 and Placing user-defined
segments, page 91.
message
Syntax #pragma message(message)
Parameters
message The message that you want to direct to the standard output
stream.
331
AFE1_AFE2-1:1
Descriptions of pragma directives
Description Use this pragma directive to make the compiler print a message to the standard output
stream when the file is compiled.
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 298.
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 295.
optimize
Syntax #pragma optimize=[goal][level][no_optimization...]
Parameters
goal Choose between:
size, optimizes for size
AFE1_AFE2-1:1
Pragma directives
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.
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. */
}
333
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.
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.
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.
AFE1_AFE2-1:1
Pragma directives
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.
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.
335
AFE1_AFE2-1:1
Descriptions of pragma directives
__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.
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.
align Specifies an alignment for the segment. The value must be a
constant integer expression to the power of two.
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
AFE1_AFE2-1:1
Pragma directives
void __memoryattribute *.
See also Dedicated segment operators, page 171 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.
STDC FENV_ACCESS
Syntax #pragma STDC FENV_ACCESS {ON|OFF|DEFAULT}
Parameters
ON Source code accesses the floating-point environment. Note
that 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.
337
AFE1_AFE2-1:1
Descriptions of pragma directives
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 that 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 295.
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 __near is defined:
#pragma type_attribute=__near
int x;
AFE1_AFE2-1:1
Pragma directives
vector
Syntax #pragma vector=vector1[, vector2, vector3, ...]
Parameters
vectorN The vector number(s) of an interrupt 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.
weak
Syntax #pragma weak symbol1[=symbol2]
Parameters
symbol1 A function or variable with external linkage.
symbol2 A defined function or variable.
339
AFE1_AFE2-1:1
Descriptions of pragma directives
AFE1_AFE2-1:1
Intrinsic functions
● Summary of intrinsic functions
341
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__delay_cycles
Syntax void __delay_cycles(unsigned long int);
Description Makes the compiler generate code that takes the given amount of cycles to perform, that
is, it inserts a time delay that lasts the specified number of cycles.
The specified value must be a constant integer expression and not an expression that is
evaluated at runtime.
__DES_decryption
Syntax unsigned long long __DES_decryption(unsigned long long data,
unsigned long long key);
where:
AFE1_AFE2-1:1
Intrinsic functions
__DES_encryption
Syntax unsigned long long __DES_encryption(unsigned long long data,
unsigned long long key);
where:
__disable_interrupt
Syntax void __disable_interrupt(void);
__enable_interrupt
Syntax void __enable_interrupt(void);
__extended_load_program_memory
Syntax unsigned char __extended_load_program_memory(unsigned char
__farflash *);
343
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__fractional_multiply_signed
Syntax signed int __fractional_multiply_signed(signed char, signed
char);
__fractional_multiply_signed_with_unsigned
Syntax signed int __fractional_multiply_signed_with_unsigned(signed
char, unsigned char);
__fractional_multiply_unsigned
Syntax unsigned int __fractional_multiply_unsigned(unsigned char,
unsigned char);
__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);
}
__indirect_jump_to
Syntax void __indirect_jump_to(unsigned long);
Description Jumps to the address specified by the argument by using the IJMP or EIJMP instruction,
depending on the generic processor option:
__insert_opcode
Syntax void __insert_opcode(unsigned short);
__lac
Syntax unsigned char __lac(unsigned char, unsigned char *);
345
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__las
Syntax unsigned char __las(unsigned char, unsigned char *);
__lat
Syntax unsigned char __lat(unsigned char, unsigned char *);
__load_program_memory
Syntax unsigned char __load_program_memory(unsigned char __flash *);
Description Returns one byte from code memory. The constants must be placed within the first 64
Kbytes of memory.
__multiply_signed
Syntax signed int __multiply_signed(signed char, signed char);
__multiply_signed_with_unsigned
Syntax signed int __multiply_signed_with_unsigned(signed char, unsigned
char);
__multiply_unsigned
Syntax unsigned int __multiply_unsigned(unsigned char, unsigned char);
AFE1_AFE2-1:1
Intrinsic functions
__no_operation
Syntax void __no_operation(void);
__require
Syntax void __require(void *);
Example In this example, the copyright message will be included in the generated binary file even
though it is not directly used.
#include <intrinsics.h>
char copyright[] = "Copyright 2011 by XXXX";
void main(void)
{
__require(copyright);
[... the rest of the program ...]
}
__restore_interrupt
Syntax void __restore_interrupt(unsigned char oldState);
347
AFE1_AFE2-1:1
Descriptions of intrinsic functions
__reverse
Syntax unsigned int __reverse(unsigned int);
Description Reverses the byte order of the value given as parameter. Avoid using __reverse in
complex expressions as it might introduce extra register copying.
__save_interrupt
Syntax unsigned char __save_interrupt(void);
Description Saves the state of the interrupt flag in the byte returned. This value can then be used for
restoring the state of the interrupt flag with the __restore_interrupt intrinsic
function.
oldState = __save_interrupt();
__disable_interrupt();
__restore_interrupt(oldState);
__set_interrupt_state
Syntax void __set_interrupt_state(__istate_t);
For information about the __istate_t type, see __get_interrupt_state, page 344.
AFE1_AFE2-1:1
Intrinsic functions
__sleep
Syntax void __sleep(void);
__swap_nibbles
Syntax unsigned char __swap_nibbles(unsigned char);
Description Swaps bit 0-3 with bit 4-7 of the parameter and returns the swapped value.
__watchdog_reset
Syntax void __watchdog_reset(void);
__xch
Syntax unsigned char __xch(unsigned char, unsigned char *);
349
AFE1_AFE2-1:1
Descriptions of intrinsic functions
AFE1_AFE2-1:1
The preprocessor
● Overview of the preprocessor
Note that backslashes can also be used. In this case, use one in include file paths and two
in source code strings.
351
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.
__CORE__
Description An integer that identifies the processor variant in use. The value reflects the setting of
the processor option -vn,
__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
#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.
__CPU__
Description A symbol that identifies the processor variant in use. The value reflects the setting of the
processor option -vn,
AFE1_AFE2-1:1
The preprocessor
__DATE__
Description A string that identifies the date of compilation, which is returned in the form
"Mmm dd yyyy", for example "Oct 30 2014".
__device__
Description An integer that identifies the processor variant in use. The value reflects the setting of
the --cpu option. device corresponds exactly to the device name, except for FpSLic,
which uses the predefined symbol __AT94Kxx__. For example, the symbol is
__AT90S2313__ when the --cpu=2313 option is used, and __ATmega163__, when
--cpu=m163 is used.
__DOUBLE__
Description An integer that identifies the size of the data type double. The symbol is defined to 32
or 64, depending on the setting of the option --64bit_doubles.
__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.
353
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. This is useful for assertions and other trace utilities. The symbol
requires that language extensions are enabled.
__HAS_EEPROM__
Description A symbol that determines whether there is internal EEPROM available or not. When this
symbol is defined, there is internal EEPROM available. When this symbol is not
defined, there is no EEPROM available.
__HAS_EIND__
Description A symbol that determines whether the instruction EIND is available or not. When this
symbol is defined, the instruction EIND is available. When this symbol is not defined,
the EIND instruction is not available.
__HAS_ELPM__
Description A symbol that determines whether the instruction ELPM is available or not. When this
symbol is defined, the instruction ELPM is available. When this symbol is not defined,
the ELPM instruction is not available.
AFE1_AFE2-1:1
The preprocessor
__HAS_ENHANCED_CORE__
Description A symbol that determines whether the enhanced core is used or not. The symbol reflects
the --enhanced_core option and is defined when the enhanced core is used. When
this symbol is not defined, the enhanced core is not used.
__HAS_FISCR__
Description A symbol that determines whether the instruction FISCR is available or not. When this
symbol is defined, the instruction FISCR is available. When this symbol is not defined,
the FISCR instruction is not available.
__HAS_MUL__
Description A symbol that determines whether the instruction MUL is available or not. When this
symbol is defined, the instruction MUL is available. When this symbol is not defined, the
MUL instruction is not available.
__HAS_RAMPD__
Description A symbol that determines whether the register RAMPD is available or not. When this
symbol is defined, the register RAMPD is available. When this symbol is not defined, the
RAMPD register is not available.
__HAS_RAMPX__
Description A symbol that determines whether the register RAMPX is available or not. When this
symbol is defined, the register RAMPX is available. When this symbol is not defined, the
RAMPX register is not available.
__HAS_RAMPY__
Description A symbol that determines whether the register RAMPY is available or not. When this
symbol is defined, the register RAMPY is available. When this symbol is not defined, the
RAMPY register is not available.
355
AFE1_AFE2-1:1
Description of predefined preprocessor symbols
__HAS_RAMPZ__
Description A symbol that determines whether the register RAMPZ is available or not. When this
symbol is defined, the register RAMPZ is available. When this symbol is not defined, the
RAMPZ register is not available.
__IAR_SYSTEMS_ICC__
Description An integer that identifies the IAR compiler platform. The current value is 9. Note that
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.
__ICCAVR__
Description An integer that is set to 1 when the code is compiled with the IAR C/C++ Compiler for
AVR.
__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.
__LITTLE_ENDIAN__
Description An integer that reflects the byte order and is defined to 1 (little-endian).
__MEMORY_MODEL__
Description An integer that identifies the memory model in use. The value reflects the setting of the
--memory_model option and is defined to 1 for the Tiny memory model, 2 for the Small
memory model, 3 for the Large memory model, and 4 for the Huge memory model.
__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
AFE1_AFE2-1:1
The preprocessor
example "void func(char)". This symbol is useful for assertions and other trace
utilities. The symbol requires that language extensions are enabled.
__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.
__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.
__TID__
Description A symbol that expands to the target identifier which contains these parts:
● t, a target identifier, which is unique for each IAR compiler. For the AVR
microcontroller, the target identifier is 9.0.
● c, the value of the --cpu or -v option.
● m, the value reflects the setting of the --memory_model option; the value is defined
to 1 for Tiny, 2 for Small, 3 for Large, and 4 for Huge.
The __TID__ value is constructed as:
((t << 8) | (c << 4) | m)
357
AFE1_AFE2-1:1
Description of predefined preprocessor symbols
To find the value of the target identifier for the current compiler, execute:
printf("%ld", (__TID__ >> 8) & 0x7F)
Note: The use of __TID__ is not recommended. We recommend that you use the
symbols __ICCAVR__ and __CORE__ instead.
__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").
__TINY_AVR__
Description A symbol that determines whether the reduced tiny AVR core is used or not. When this
symbol is defined, the reduced tiny AVR core is used. When this symbol is not defined,
the reduced tiny AVR core is not used.
__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.
__VERSION_1_CALLS__
Description A symbol that expands to 1 if the used calling convention is the old calling convention
used in compiler version 1.x. If zero, the new calling convention is used. For more
information about calling conventions, see Calling convention, page 155.
AFE1_AFE2-1:1
The preprocessor
__XMEGA_CORE__
Description A symbol that determines whether the xmega core is used or not. When this symbol is
defined, the xmega core is used. When this symbol is not defined, the xmega core is not
used.
__XMEGA_USB__
Description A symbol that determines whether the xmega usb core is used or not. When this symbol
is defined, the xmega usb core is used. When this symbol is not defined, the xmega usb
core is not used.
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 that 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.
359
AFE1_AFE2-1:1
Descriptions of miscellaneous preprocessor extensions
#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.
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.
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
361
AFE1_AFE2-1:1
C/C++ standard library overview
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
● Rand functions—rand, srand
● Time functions—asctime, localtime, gmtime, mktime
● The miscellaneous functions atexit, perror, strerror, strtok
AFE1_AFE2-1:1
C/C++ standard library functions
● Functions that use files or the heap in some way. This includes scanf, sscanf,
getchar, getwchar, putchar, and putwchar. In addition, if you are using the
options --enable_multibyte and --dlib_config=Full, the printf and
sprintf functions (or any variants) can also use the heap.
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.
363
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 367.
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 40: Traditional Standard C header files—DLIB
AFE1_AFE2-1:1
C/C++ standard library functions
365
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
fenv.h
In fenv.h, trap handling support for floating-point numbers is defined with the
functions fegettrapenable and fegettrapdisable. No floating-point status flags
are supported.
367
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
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.
369
AFE1_AFE2-1:1
AVR-specific library functions
● The system startup code; see the chapter The CLIB runtime environment in this
guide.
● Runtime support libraries; for example low-level floating-point routines.
● Intrinsic functions, allowing low-level use of AVR features. See the chapter
Intrinsic functions for more information.
● Special compiler support for accessing strings in flash memory, see AVR-specific
library functions, page 370.
* 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
C/C++ standard library functions
they allow access to both flash and data memory. Both the _P functions and the _G
functions are available in both the IAR CLIB Library and the IAR DLIB Library.
memcmp_G
Syntax int memcmp_G(const void *s1, const void __generic *s2, size_t
n);
Description Identical to memcmp except that s2 can be located in flash or data memory.
memcpy_G
Syntax void * memcpy_G(void *s1, const void __generic *s2, size_t n);
Description Identical to memcpy except that it copies string s2 in flash or data memory to the
location that s1 points to in data memory.
memcpy_P
Syntax void * memcpy_P(void *s1, PGM_P s2, size_t n);
Description Identical to memcpy except that it copies string s2 in flash memory to the location that
s1 points to in data memory.
printf_P
Syntax int printf_P(PGM_P __format,…);
Description Similar to printf except that the format string is in flash memory, not in data memory.
For information about how to override default formatter, see Formatters for printf, page
113.
puts_G
Syntax int puts_G(const char __generic *s);
Description Identical to puts except that the string to be written can be in flash or data memory.
371
AFE1_AFE2-1:1
AVR-specific library functions
puts_P
Syntax int puts_P(PGM_P __s);
Description Identical to puts except that the string to be written is in flash memory, not in data
memory.
scanf_P
Syntax int scanf_P(PGM_P __format,…);
Description Identical to scanf except that the format string is in flash memory, not in data memory.
For information about how to override the default formatter, see Formatters for scanf,
page 114.
sprintf_P
Syntax int sprintf_P(char *__s, PGM_P __format,…);
Description Identical to sprintf except that the format string is in flash memory, not in data
memory.
sscanf_P
Syntax int sscanf_P(const char *__s, PGM_P __format,…);
Description Identical to sscanf except that the format string is in flash memory, not in data memory.
strcat_G
Syntax char *strcat_G(char *s1, const char __generic *s2);
Description Identical to strcat except that string s2 can be in flash or data memory.
strcmp_G
Syntax int strcmp_G(const char *s1, const char __generic *s2);
Description Identical to strcmp except that string s2 can be in flash or data memory.
AFE1_AFE2-1:1
C/C++ standard library functions
strcmp_P
Syntax int strcmp_P(const char *s1, PGM_P s2);
Description Identical to strcmp except that string s2 is in flash memory, not in data memory.
strcpy_G
Syntax char *strcpy_G(char *s1, const char __generic *s2);
Description Identical to strcpy except that the string s2 being copied can be in flash or data
memory.
strcpy_P
Syntax char * strcpy_P(char *s1, PGM_P s2);
Description Identical to strcpy except that the string s2 being copied is in flash memory, not in data
memory.
strerror_P
Syntax PGM_P strerror_P(int errnum);
Description Identical to strerror except that the string returned is in flash memory, not in data
memory.
strlen_G
Syntax size_t strlen_G(const char __generic *s);
Description Identical to strlen except that the string being tested can be in flash or data memory.
strlen_P
Syntax size_t strlen_P(PGM_P s);
Description Identical to strlen except that the string being tested is in flash memory, not in data
memory.
373
AFE1_AFE2-1:1
AVR-specific library functions
strncat_G
Syntax char *strncat_G(char *s1, const char __generic *s2, size_t n);
Description Identical to strncmp except that the string s2 can be in flash or data memory.
strncmp_G
Syntax int strncmp_G(const char *s1, const char __generic *s2, size_t
n);
Description Identical to strncmp except that the string s2 can be in flash or data memory.
strncmp_P
Syntax int strncmp_P(const char *s1, PGM_P s2, size_t n);
Description Identical to strncmp except that the string s2 is in flash memory, not in data memory.
strncpy_G
Syntax char *strncpy_G(char *s1, const char __generic *s2, size_t n);
Description Identical to strncpy except that the source string s2 can be in flash or data memory.
strncpy_P
Syntax char * strncpy_P(char *s1, PGM_P s2, size_t n);
Description Identical to strncpy except that the source string s2 is in flash memory, not in data
memory.
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
CHECKSUM Holds the checksum generated by the linker.
CODE Holds the program code.
CSTACK Holds the stack used by C or C++ programs.
DIFUNCT Holds pointers to code, typically C++ constructors, that should be
executed by the system startup code before main is called.
EEPROM_I Holds static and global initialized variables that have the memory
attribute __eeprom.
EEPROM_N Holds __no_initstatic and global variables that have the memory
attribute __eeprom.
FARCODE Holds program code declared __farfunc.
FAR_C Holds constant data that has the memory attribute __far.
FAR_F Holds static and global variables that have the memory attribute
__farflash.
FAR_HEAP Holds the far heap.
FAR_I Holds the static and global initialized variables that have the memory
attribute __far.
FAR_ID Holds initial values for static and global initialized variables in FAR_I.
FAR_N Holds __no_init static and global variables that have the memory
attribute __far.
FAR_Z Holds zero-initialized static and global variables that have the memory
attribute __far.
HEAP Holds the heap used for dynamically allocated data using the CLIB library.
Table 45: Segment summary
375
AFE1_AFE2-1:1
Summary of segments
Segment Description
HUGE_C Holds constant data that has the memory attribute__huge.
HUGE_F Holds static and global __hugeflash variables.
HUGE_HEAP Holds the heap used for dynamically allocated data in huge memory using
the DLIB library.
HUGE_I Holds static and global initialized variables that have the memory
attribute__huge.
HUGE_ID Holds initial values for static and global initialized variables in HUGE_I.
HUGE_N Holds __no_initstatic and global variables that have the memory
attribute__huge.
HUGE_Z Holds zero-initialized static and global variables that have the memory
attribute __huge.
INITTAB Contains compiler-generated table entries that describe the segment
initialization that will be performed at system startup.
INTVEC Contains the reset and interrupt vectors.
NEAR_C Holds constant data that has the memory attribute __tiny and
__near.
NEAR_F Holds static and global __flash variables.
NEAR_HEAP Holds the heap used for dynamically allocated data in near memory using
the DLIB library.
NEAR_I Holds static and global initialized variables that have the memory
attribute __near.
NEAR_ID Holds initial values for static and global initialized variables in NEAR_I.
NEAR_N Holds __no_initstatic and global variables that have the memory
attribute __near.
NEAR_Z Holds zero-initialized static and global variables that have the memory
attribute __near.
RSTACK Holds the internal return stack.
SWITCH Holds switch tables for all functions.
TINY_F Holds static and global __tinyflash variables.
TINY_HEAP Holds the heap used for dynamically allocated data in tiny memory using
the DLIB library.
TINY_I Holds static and global initialized variables that have the memory
attribute __tiny.
TINY_ID Holds initial values for static and global variables in TINY_I.
Table 45: Segment summary (Continued)
AFE1_AFE2-1:1
Segment reference
Segment Description
TINY_N Holds __no_init static and global variables that have the memory
attribute__tiny.
TINY_Z Holds zero-initialized static and global variables that have the memory
attribute __tiny.
Table 45: 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 89 and Using the
-P command for packed placement, page 89, 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 72.
For information about how to define segments in the linker configuration file, see
Linking your application, page 87.
For more information about the extended keywords mentioned here, see the chapter
Extended keywords.
CHECKSUM
Description Holds the checksum bytes generated by the linker. This segment also holds the
__checksum symbol. Note that the size of this segment is affected by the linker option
-J.
377
AFE1_AFE2-1:1
Descriptions of segments
CODE
Description Holds __nearfunc program code, except the code for system initialization.
Memory placement Flash. This segment must be placed within the address range 0x0–0x01FFFE.
CSTACK
Description Holds the internal data stack.
Memory placement Data. The address range depends on the memory model:
In the Tiny memory model, this segment must be placed within the address range
0x0-0xFF.
In the Small memory model, this segment must be placed within the address range
0x0-0xFFFF.
In the Large and Huge memory models, this segment must be placed within the address
range 0x0-0xFFFFFF. In the Large and Huge memory models, the stack can be a
maximum of 64 Kbytes, and CSTACK must not cross a 64-Kbyte boundary.
DIFUNCT
Description Holds the dynamic initialization vector used by C++.
Memory placement This segment must be placed in the first 64 Kbytes of memory.
AFE1_AFE2-1:1
Segment reference
EEPROM_I
Description Holds __eeprom static and global initialized variables initialized by copying from the
segment EEPROM_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 not copied to EEPROM during system startup. Instead it is used for
programming the EEPROM during the download of the code.
Memory placement This segment must be placed in EEPROM. Use the command line option
--eeprom_size to set the address range for this segment.
EEPROM_N
Description Holds static and global __no_init __eeprom variables.
Memory placement This segment must be placed in EEPROM. Use the command line option
--eeprom_size to set the address range for this segment.
FARCODE
Description Holds __farfunc program code. The __farfunc memory attribute is available when
using the -v5 and -v6 options, in which case the __farfunc is implicitly used for all
functions.
Memory placement This segment must be placed within the address range 0x0–0x7FFFFE in flash memory.
379
AFE1_AFE2-1:1
Descriptions of segments
FAR_C
Description Holds __far constant data. This can include constant variables, string and aggregate
literals, etc.
Note: This segment is located in external ROM. Systems without external ROM cannot
use this segment.
Memory placement External ROM. This segment must be placed within the address range 0x0–0xFFFFFF.
FAR_F
Description Holds the static and global __farflash variables and aggregate initializers.
Memory placement Flash. This segment must be placed within the address range 0x0–0x7FFFFF.
FAR_HEAP
Description Holds the heap used for dynamically allocated data in far memory, in other words data
allocated by far_malloc and far_free, and in C++, new and delete.
Note: This segment is only used when you use the DLIB library.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
See also Setting up heap memory, page 92 and New and Delete operators, page 181.
AFE1_AFE2-1:1
Segment reference
FAR_I
Description Holds __far static and global initialized variables initialized by copying from the
segment FAR_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.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
FAR_ID
Description Holds initial values for __far static and global variables in the FAR_I segment. These
values are copied from FAR_ID to FAR_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.
Memory placement Flash. This segment must be placed within the address range 0x0–0x7FFFFF.
FAR_N
Description Holds static and global __no_init __far variables.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
381
AFE1_AFE2-1:1
Descriptions of segments
FAR_Z
Description Holds zero-initialized __far static and global variables. 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.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
HEAP
Description Holds the heap used for dynamically allocated data, in other words data allocated by
malloc and free.
Note: This segment is only used when you use the CLIB library.
Memory placement Data. The address range depends on the memory model.
In the Tiny memory model, this segment must be placed within the address range
0x0-0xFF.
In the Small memory model, this segment must be placed within the address range
0x0-0xFFFF.
In the Large and Huge memory models, this segment must be placed within the address
range 0x0-0xFFFFFF.
See also Setting up heap memory, page 92 and New and Delete operators, page 181.
HUGE_C
Description Holds __huge constant data. This can include constant variables, string and aggregate
literals, etc.
AFE1_AFE2-1:1
Segment reference
Note: This segment is located in external ROM. Systems without external ROM cannot
use this segment.
Memory placement External ROM. This segment must be placed within the address range 0x0–0xFFFFFF.
HUGE_F
Description Holds the static and global __hugeflash variables and aggregate initializers.
Memory placement Flash. This segment must be placed within the address range 0x0–0xFFFFFF.
HUGE_HEAP
Description Holds the heap used for dynamically allocated data in huge memory, in other words data
allocated by huge_malloc and huge_free, and in C++, new and delete.
Note: This segment is only used when you use the DLIB library.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
See also Setting up heap memory, page 92 and New and Delete operators, page 181.
HUGE_I
Description Holds __huge static and global initialized variables initialized by copying from the
segment HUGE_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.
383
AFE1_AFE2-1:1
Descriptions of segments
When the -y compiler option is used, __huge constant data is located in this segment.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
HUGE_ID
Description Holds initial values for __huge static and global variables in the HUGE_I segment.
These values are copied from HUGE_ID to HUGE_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.
Memory placement Flash. This segment must be placed within the address range 0x0–0x7FFFFF.
HUGE_N
Description Holds static and global __no_init __huge variables.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
HUGE_Z
Description Holds zero-initialized __huge static and global variables. 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
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFFFF.
INITTAB
Description Holds compiler-generated table entries that describe the segment initialization which
will be performed at system startup.
Memory placement Flash. This segment must be placed within the address range 0x0–0xFFFF (0x7FFFFF
if farflash is enabled).
INTVEC
Description Holds the interrupt vector table generated by the use of the __interrupt extended
keyword in combination with the #pragma vector directive.
NEAR_C
Description Holds __tiny and __near constant data. This can include constant variables, string
and aggregate literals, etc. TINY_I is copied from this segment, because TINY_C is not
a possible segment.
Note: This segment is located in external ROM. Systems without external ROM cannot
use this segment.
Memory placement External ROM. This segment must be placed within the address range 0x0–0xFFFF.
385
AFE1_AFE2-1:1
Descriptions of segments
NEAR_F
Description Holds the static and global __flash variables and aggregate initializers.
Memory placement Flash. This segment must be placed within the address range 0x0–0xFFFF.
NEAR_HEAP
Description Holds the heap used for dynamically allocated data in near memory, in other words data
allocated by near_malloc and near_free, and in C++, new and delete.
Note: This segment is only used when you use the DLIB library.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFF.
See also Setting up heap memory, page 92 and New and Delete operators, page 181.
NEAR_I
Description Holds __near static and global initialized variables initialized by copying from the
segment NEAR_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.
When the -y compiler option is used, NEAR_C data (__near) is located in this segment.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFF.
AFE1_AFE2-1:1
Segment reference
NEAR_ID
Description Holds initial values for __near static and global variables in the NEAR_I segment.
These values are copied from NEAR_ID to NEAR_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.
Memory placement Flash. This segment must be placed within the address range 0x0–0x7FFFFF.
NEAR_N
Description Holds static and global __no_init __near variables.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFF.
NEAR_Z
Description Holds zero-initialized __near static and global variables. 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.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFF.
387
AFE1_AFE2-1:1
Descriptions of segments
RSTACK
Description Holds the internal return stack.
Memory placement Data. This segment must be placed within the address range 0x0–0xFFFF.
SWITCH
Description Holds switch tables for all functions.
The SWITCH segment is for compiler internal use only and should always be defined.
The segment allocates, if necessary, jump tables for C/C++ switch statements.
Memory placement Flash. This segment must be placed within the address range 0x0–0xFFFF. If the
__farflash extended keyword and the --enhanced_core option are used, the
segment must be placed within the range 0x0–0x7FFFFF. This segment must not cross
a 64-Kbyte boundary.
TINY_F
Description Holds the static and global __tinyflash variables and aggregate initializers.
Memory placement Flash. This segment must be placed within the address range 0x0–0xFF.
AFE1_AFE2-1:1
Segment reference
TINY_HEAP
Description Holds the heap used for dynamically allocated data in tiny memory, in other words data
allocated by tiny_malloc and tiny_free, and in C++, new and delete.
Note: This segment is only used when you use the DLIB library.
Memory placement Data. This segment must be placed within the address range 0x0–0xFF.
See also Setting up heap memory, page 92 and New and Delete operators, page 181.
TINY_I
Description Holds __tiny static and global initialized variables initialized by copying from the
segment TINY_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.
When the -y compiler option is used, NEAR_C data is located in this segment.
Memory placement Data. This segment must be placed within the address range 0x0–0xFF.
TINY_ID
Description Holds initial values for __tiny static and global variables in the TINY_I segment.
These values are copied from TINY_ID to TINY_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.
Memory placement Flash. This segment must be placed within the address range 0x0–0x7FFFFF.
389
AFE1_AFE2-1:1
Descriptions of segments
TINY_N
Description Holds static and global __no_init __tiny variables.
Memory placement Data. This segment must be placed within the address range 0x0–0xFF.
TINY_Z
Description Holds zero-initialized __tiny static and global variables. 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.
Memory placement Data. This segment must be placed within the address range 0x0–0xFF.
AFE1_AFE2-1:1
The stack usage control file
● Overview
● Syntactic components
Before you read this chapter, see Stack usage analysis, page 79.
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 395
func-spec See func-spec, page 395
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.
391
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, stack) The stack depth of stack in 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
stack) for each call graph root function in the category.
size("SEGMENT") The size of the segment.
In the example, maxstack is the deepest call chain of the program on the CSTACK stack
plus the total stack usage on the RSTACK stack plus 1024.
AFE1_AFE2-1:1
The stack usage control file
exclude directive
Syntax exclude func-spec [, func-spec... ];
Parameters
func-spec See func-spec, page 395
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 395
func-spec See func-spec, page 395
call-info See call-info, page 396
stack-size See stack-size, page 397
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 395
393
AFE1_AFE2-1:1
Stack usage control directives
Description Specifies the maximum number of iterations through any of the cycles in the recursion
nest of which the function is a member.
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 395
module-spec See module-spec, page 396
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 395
called-func See func-spec, page 395
AFE1_AFE2-1:1
The stack usage control file
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
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.
395
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 that when using multi-file compilation (--mfc), multiple files are compiled into a
single module, named after the first file.
[file.r90]
[file.r90(lib.a)]
["D:\C1\test\file.r90"]
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.r90
"file-1.r90"
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 (CSTACK size, RSTACK size)
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
397
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 141.
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.
399
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 Customizing
__low_level_init, page 122.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.3 IDENTIFIERS
J.3.4 CHARACTERS
401
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.5 INTEGERS
403
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
ptrdiff_t (6.5.6)
For information about ptrdiff_t, see ptrdiff_t, page 289.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
J.3.8 HINTS
405
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
407
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 129 and raise, page 127, respectively.
409
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 100.
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 100.
AFE1_AFE2-1:1
Implementation-defined behavior for Standard C
411
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
124.
J.3.13 ARCHITECTURE
For information about sizes, ranges, etc for all basic types, see Data representation, page
281.
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
413
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 Customizing
__low_level_init, page 122. To change this behavior for the CLIB runtime environment,
see Customizing system initialization, page 147.
415
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
417
AFE1_AFE2-1:1
Descriptions of implementation-defined behavior
FLOATING POINT
AFE1_AFE2-1:1
Implementation-defined behavior for C89
REGISTERS
419
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
421
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 129 and raise, page 127, 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 100.
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.
423
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 100.
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 100.
%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 125.
system() (7.10.4.5)
How the command processor works depends on how you have implemented the system
function. See system, page 130.
clock() (7.12.2.1)
From where the system clock starts counting depends on how you have implemented the
clock function. See clock, page 124.
425
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 *'.
427
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
single-value initialization . . . . . . . . . . . . . . . . . . . . . . . 173
A asm, __asm (language extension) . . . . . . . . . . . . . . . . . . . 151
abort assembler code
implementation-defined behavior . . . . . . . . . . . . . . . . 411 calling from C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
implementation-defined behavior in C89 (CLIB) . . . . 427 calling from C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
implementation-defined behavior in C89 (DLIB) . . . . 424 inserting inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
system termination (DLIB) . . . . . . . . . . . . . . . . . . . . . 121 assembler directives
absolute location for call frame information . . . . . . . . . . . . . . . . . . . . . . 165
data, placing at (@) . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 for static overlay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
language support for . . . . . . . . . . . . . . . . . . . . . . . . . . 170 using in inline assembler code . . . . . . . . . . . . . . . . . . . 152
#pragma location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 assembler instructions
address spaces, managing multiple . . . . . . . . . . . . . . . . . . . 96 inserting inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
addressing. See memory types, data models, assembler labels
and code models default for application startup . . . . . . . . . . . . . . . . . . . . 48
algorithm (STL header file) . . . . . . . . . . . . . . . . . . . . . . . 366 making public (--public_equ) . . . . . . . . . . . . . . . . . . . . 269
alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 assembler language interface . . . . . . . . . . . . . . . . . . . . . . 149
forcing stricter (#pragma data_alignment) . . . . . . . . . . 323 calling convention. See assembler code
of an object (__ALIGNOF__) . . . . . . . . . . . . . . . . . . . 170 assembler list file, generating . . . . . . . . . . . . . . . . . . . . . . 256
of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 assembler output file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
alignment (pragma directive) . . . . . . . . . . . . . . . . . . 407, 421 asserts
__ALIGNOF__ (operator) . . . . . . . . . . . . . . . . . . . . . . . . 170 implementation-defined behavior of . . . . . . . . . . . . . . 408
anonymous structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 implementation-defined behavior of in C89, (CLIB) . . 426
anonymous symbols, creating . . . . . . . . . . . . . . . . . . . . . . 167 implementation-defined behavior of in C89, (DLIB) . . 422
ANSI C. See C89 including in application . . . . . . . . . . . . . . . . . . . . . . . . 359
application assert.h (CLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 370
building, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 assert.h (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 364
execution, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . 44 __assignment_by_bitwise_copy_allowed, symbol used
startup and termination (CLIB) . . . . . . . . . . . . . . . . . . 145 in library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
startup and termination (DLIB) . . . . . . . . . . . . . . . . . . 118 @ (operator)
ARGFRAME (assembler directive) . . . . . . . . . . . . . . . . . 165 placing at absolute address . . . . . . . . . . . . . . . . . . . . . . 211
argv (argument), implementation-defined behavior . . . . . 400 placing in segments . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
arrays atomic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
designated initializers in . . . . . . . . . . . . . . . . . . . . . . . 167 __monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
hints about index type . . . . . . . . . . . . . . . . . . . . . . . . . 206 attributes
implementation-defined behavior . . . . . . . . . . . . . . . . 404 object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
implementation-defined behavior in C89 . . . . . . . . . . . 419 type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
incomplete at end of structs . . . . . . . . . . . . . . . . . . . . . 167 auto variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
non-lvalue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 at function entrance . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
of incomplete types . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 programming hints for efficient code . . . . . . . . . . . . . . 219
using in inline assembler code . . . . . . . . . . . . . . . . . . . 152
429
DRX-2
AVR C language, overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
supported devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 call frame information . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
in assembler list file . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
DRX-2
Index
431
DRX-2
compiling CPU, specifying on command line for compiler . . . . . . . . 242
from the command line . . . . . . . . . . . . . . . . . . . . . . . . . 48 cross call (compiler transformation) . . . . . . . . . . . . . . . . . 218
syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 --cross_call_passes (compiler option) . . . . . . . . . . . . . . . . 242
complex numbers, supported in Embedded C++ . . . . . . . . 176 csetjmp (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 367
complex (library header file). . . . . . . . . . . . . . . . . . . . . . . 365 csignal (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 367
complex.h (library header file) . . . . . . . . . . . . . . . . . . . . . 364 cspy_support (pragma directive) . . . . . . . . . . . . . . . . 407, 421
compound literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 CSTACK (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
computer style, typographic convention . . . . . . . . . . . . . . . 28 See also stack
configuration cstartup (system startup code)
basic project settings . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 customizing system initialization . . . . . . . . . . . . . . . . . 122
__low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 source files for (CLIB) . . . . . . . . . . . . . . . . . . . . . . . . . 145
configuration symbols source files for (DLIB). . . . . . . . . . . . . . . . . . . . . . . . . 118
for file input and output . . . . . . . . . . . . . . . . . . . . . . . . 133 cstat_disable (pragma directive) . . . . . . . . . . . . . . . . . . . . 319
for locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 cstat_enable (pragma directive) . . . . . . . . . . . . . . . . . . . . 319
for printf and scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 cstat_restore (pragma directive) . . . . . . . . . . . . . . . . . . . . 319
for strtod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 cstat_suppress (pragma directive) . . . . . . . . . . . . . . . . . . . 319
in library configuration files. . . . . . . . . . . . . . . . . . . . . 109 cstdarg (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 367
const cstdbool (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . 367
declaring objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 cstddef (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . 367
non-top level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 cstdio (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . . 367
constants, placing in named segment . . . . . . . . . . . . . . . . 323 cstdlib (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . . 367
__constrange(), symbol used in library . . . . . . . . . . . . . . . 369 cstring (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . . 367
__construction_by_bitwise_copy_allowed, symbol used ctime (DLIB header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 367
in library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 ctype.h (library header file) . . . . . . . . . . . . . . . . . . . . 364, 370
constseg (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . 323 cwctype.h (library header file) . . . . . . . . . . . . . . . . . . . . . 367
const_cast (cast operator) . . . . . . . . . . . . . . . . . . . . . . . . . 176 ?C_EXIT (assembler label) . . . . . . . . . . . . . . . . . . . . . . . . 147
contents, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 ?C_GETCHAR (assembler label) . . . . . . . . . . . . . . . . . . . 147
control characters, C_INCLUDE (environment variable) . . . . . . . . . . . . . . . . 228
implementation-defined behavior . . . . . . . . . . . . . . . . . . . 413 ?C_PUTCHAR (assembler label) . . . . . . . . . . . . . . . . . . . 147
conventions, used in this guide . . . . . . . . . . . . . . . . . . . . . . 28 C-SPY
copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 debug support for C++ . . . . . . . . . . . . . . . . . . . . . . . . . 183
cos (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 interface to system termination . . . . . . . . . . . . . . . . . . 122
cos (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118 low-level interface (CLIB) . . . . . . . . . . . . . . . . . . . . . . 147
cosf (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118 C-STAT for static analysis, documentation for . . . . . . . . . . 26
cosl (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118 C++
__COUNTER__ (predefined symbol). . . . . . . . . . . . . . . . 352 See also Embedded C++ and Extended Embedded C++
__cplusplus (predefined symbol) . . . . . . . . . . . . . . . . . . . 352 absolute location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
__CPU__ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 352 calling convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
--cpu (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 dynamic initialization in . . . . . . . . . . . . . . . . . . . . . . . . 93
CPU, identifying (__CPU__) . . . . . . . . . . . . . . . . . . . . . . 352
DRX-2
Index
433
DRX-2
--diag_error (compiler option) . . . . . . . . . . . . . . . . . . . . . 245 domain errors, implementation-defined behavior in C89
diag_error (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 327 (CLIB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
--diag_remark (compiler option) . . . . . . . . . . . . . . . . . . . . 245 domain errors, implementation-defined behavior in C89
diag_remark (pragma directive) . . . . . . . . . . . . . . . . . . . . 327 (DLIB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
--diag_suppress (compiler option) . . . . . . . . . . . . . . . . . . 246 double (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
diag_suppress (pragma directive) . . . . . . . . . . . . . . . . . . . 327 configuring size of floating-point type . . . . . . . . . . . . . . 50
--diag_warning (compiler option) . . . . . . . . . . . . . . . . . . . 246 --do_cross_call (compiler option) . . . . . . . . . . . . . . . . . . . 250
diag_warning (pragma directive) . . . . . . . . . . . . . . . . . . . 328 do_not_instantiate (pragma directive) . . . . . . . . . . . . 407, 421
DIFUNCT (segment) . . . . . . . . . . . . . . . . . . . . . . . . . 93, 378 DW (directive) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
directives dynamic initialization . . . . . . . . . . . . . . . . . . . . . . . . 118, 145
function for static overlay . . . . . . . . . . . . . . . . . . . . . . 165 and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36, 319 dynamic memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
directory, specifying as parameter . . . . . . . . . . . . . . . . . . 234
--disable_all_program_memory_load_instructions (compiler
option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 E
--disable_direct_mode (compiler option) . . . . . . . . . . . . . 247 -e (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
__disable_interrupt (intrinsic function) . . . . . . . . . . . . . . . 343 early_initialization (pragma directive) . . . . . . . . . . . 407, 421
--disable_library_knowledge (compiler option) . . . . . . . . 247 --ec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 250
--disable_mul (compiler option) . . . . . . . . . . . . . . . . . . . . 247 edition, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
--disable_spm (compiler option) . . . . . . . . . . . . . . . . . . . . 248 --eecr_address (compiler option) . . . . . . . . . . . . . . . . . . . 251
--discard_unused_publics (compiler option) . . . . . . . . . . . 248 --eec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 251
disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 __eeprom (extended keyword) . . . . . . . . . . . . . . . . . . . . . 300
DLIB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 EEPROM_I (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 EEPROM_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 379
configuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108, 249 --eeprom_size (compiler option) . . . . . . . . . . . . . . . . . . . . 251
naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 ELPM (instruction) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
reference information. See the online help system . . . . 361 Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
runtime environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 differences from C++ . . . . . . . . . . . . . . . . . . . . . . . . . . 176
--dlib (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . 248 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
--dlib_config (compiler option). . . . . . . . . . . . . . . . . . . . . 249 language extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
DLib_Defaults.h (library configuration file) . . . . . . . . . . . 109 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
__DLIB_FILE_DESCRIPTOR (configuration symbol) . . 133 embedded systems, IAR special support for . . . . . . . . . . . . 36
document conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 __embedded_cplusplus (predefined symbol) . . . . . . . . . . 353
documentation --enable_external_bus (compiler option) . . . . . . . . . . . . . 252
contents of this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 __enable_interrupt (intrinsic function) . . . . . . . . . . . . . . . 343
how to use this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 --enable_multibytes (compiler option) . . . . . . . . . . . . . . . 252
overview of guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 --enable_restrict (compiler option) . . . . . . . . . . . . . . . . . . 253
who should read this . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 enabling restrict keyword . . . . . . . . . . . . . . . . . . . . . . . . . 253
domain errors, implementation-defined behavior . . . . . . . 408 endianness. See byte order
DRX-2
Index
435
DRX-2
FAR_Z (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 382, 384 floating-point constants
fatal error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 hexadecimal notation . . . . . . . . . . . . . . . . . . . . . . . . . . 167
fdopen, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
fegettrapdisable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 floating-point environment, accessing or not . . . . . . . . . . 338
fegettrapenable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 floating-point expressions
FENV_ACCESS, implementation-defined behavior . . . . 404 contracting or not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
fenv.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 364 floating-point format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
additional C functionality. . . . . . . . . . . . . . . . . . . . . . . 367 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206–207
fgetpos (library function), implementation-defined implementation-defined behavior . . . . . . . . . . . . . . . . 403
behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 implementation-defined behavior in C89 . . . . . . . . . . . 418
fgetpos (library function), implementation-defined special cases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
behavior in C89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 32-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
field width, library support for . . . . . . . . . . . . . . . . . . . . . 144 64-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
__FILE__ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 353 floating-point numbers, support for in printf formatters . . 144
file buffering, implementation-defined behavior . . . . . . . . 409 floating-point status flags . . . . . . . . . . . . . . . . . . . . . . . . . 367
file dependencies, tracking . . . . . . . . . . . . . . . . . . . . . . . . 244 floating-point type, configuring size of double . . . . . . . . . . 50
file input and output float.h (library header file) . . . . . . . . . . . . . . . . . . . . 364, 370
configuration symbols for . . . . . . . . . . . . . . . . . . . . . . 133 FLT_EVAL_METHOD, implementation-defined
file paths, specifying for #include files . . . . . . . . . . . . . . . 255 behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403, 408, 412
file position, implementation-defined behavior . . . . . . . . . 409 FLT_ROUNDS, implementation-defined
file streams lock interface . . . . . . . . . . . . . . . . . . . . . . . . . 138 behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403, 412
file systems in C89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 fmod (library function),
file (zero-length), implementation-defined behavior . . . . . 410 implementation-defined behavior in C89 . . . . . . . . . 422, 426
filename for loops, declarations in . . . . . . . . . . . . . . . . . . . . . . . . . . 167
extension for device description files . . . . . . . . . . . . . . . 36 --force_switch_type (compiler option) . . . . . . . . . . . . . . . 254
extension for header files . . . . . . . . . . . . . . . . . . . . . . . . 35 formats
of object file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 floating-point values . . . . . . . . . . . . . . . . . . . . . . . . . . 285
search procedure for. . . . . . . . . . . . . . . . . . . . . . . . . . . 228 standard IEEE (floating point) . . . . . . . . . . . . . . . . . . . 285
specifying as parameter . . . . . . . . . . . . . . . . . . . . . . . . 234 _formatted_write (library function) . . . . . . . . . . . . . . . . . 143
filenames (legal), implementation-defined behavior . . . . . 410 FP_CONTRACT, implementation-defined behavior . . . . 404
fileno, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 __fractional_multiply_signed (intrinsic function) . . . . . . . 344
files, implementation-defined behavior __fractional_multiply_signed_with_unsigned (intrinsic
handling of temporary . . . . . . . . . . . . . . . . . . . . . . . . . 410 function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
multibyte characters in . . . . . . . . . . . . . . . . . . . . . . . . . 410 __fractional_multiply_unsigned (intrinsic function) . . . . . 344
opening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 fragmentation, of heap memory . . . . . . . . . . . . . . . . . . . . . 62
__flash (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . 304 free (library function). See also heap . . . . . . . . . . . . . . . . . 61
flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 fsetpos (library function), implementation-defined
library routines for accessing . . . . . . . . . . . . . . . . . . . . 370 behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
placing aggregate initializers . . . . . . . . . . . . . . . . . . . . 256 fstream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 365
float (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 ftell (library function), implementation-defined behavior . 411
DRX-2
Index
437
DRX-2
__HAS_RAMPZ__ (predefined symbol) . . . . . . . . . . . . . 356 __huge (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . 305
hdrstop (pragma directive) . . . . . . . . . . . . . . . . . . . . 407, 421 __hugeflash (extended keyword) . . . . . . . . . . . . . . . . . . . 306
header files HUGE_C (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 HUGE_F (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 HUGE_HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . . . 383
library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 HUGE_I (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
special function registers . . . . . . . . . . . . . . . . . . . . . . . 222 HUGE_ID (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 HUGE_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . . 384, 387
DLib_Defaults.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
including stdbool.h for bool . . . . . . . . . . . . . . . . . . . . . 283
including stddef.h for wchar_t . . . . . . . . . . . . . . . . . . . 284 I
header names, implementation-defined behavior . . . . . . . 406 -I (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
--header_context (compiler option) . . . . . . . . . . . . . . . . . . 255 IAR Command Line Build Utility. . . . . . . . . . . . . . . . . . . 109
heap IAR Postlink (utility) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
dynamic memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 IAR Systems Technical Support . . . . . . . . . . . . . . . . . . . . 232
segments for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 iarbuild.exe (utility) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
storing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 __iar_cos_accurate (library routine) . . . . . . . . . . . . . . . . . 118
VLA allocated on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 __iar_cos_accuratef (library routine) . . . . . . . . . . . . . . . . 118
heap segments __iar_cos_accuratef (library function) . . . . . . . . . . . . . . . 362
CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 __iar_cos_accuratel (library routine) . . . . . . . . . . . . . . . . 118
DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 __iar_cos_accuratel (library function) . . . . . . . . . . . . . . . 362
FAR_F (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 __iar_cos_small (library routine) . . . . . . . . . . . . . . . . . . . 117
FAR_HEAP (segment) . . . . . . . . . . . . . . . . . . . . 380, 382 __iar_cos_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117
HUGE_F (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 __iar_cos_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117
HUGE_HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . 383 __IAR_DLIB_PERTHREAD_INIT_SIZE (macro) . . . . . 139
NEAR_F (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 386 __IAR_DLIB_PERTHREAD_SIZE (macro) . . . . . . . . . . 139
NEAR_HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . 386 __IAR_DLIB_PERTHREAD_SYMBOL_OFFSET
placing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 (symbolptr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
TINY_F (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388 __iar_exp_small (library routine) . . . . . . . . . . . . . . . . . . . 117
TINY_HEAP (segment). . . . . . . . . . . . . . . . . . . . . . . . 389 __iar_exp_smallf (library routine) . . . . . . . . . . . . . . . . . . 117
heap size __iar_exp_smalll (library routine) . . . . . . . . . . . . . . . . . . 117
and standard I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 __iar_log_small (library routine) . . . . . . . . . . . . . . . . . . . 117
changing default. . . . . . . . . . . . . . . . . . . . . . . . . . . . 91–92 __iar_log_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117
HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 __iar_log_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117
heap (zero-sized), implementation-defined behavior . . . . 411 __iar_log10_small (library routine) . . . . . . . . . . . . . . . . . 117
hints __iar_log10_smallf (library routine) . . . . . . . . . . . . . . . . . 117
for good code generation . . . . . . . . . . . . . . . . . . . . . . . 218 __iar_log10_smalll (library routine) . . . . . . . . . . . . . . . . . 117
implementation-defined behavior . . . . . . . . . . . . . . . . 405 __iar_Powf (library routine) . . . . . . . . . . . . . . . . . . . . . . . 118
using efficient data types . . . . . . . . . . . . . . . . . . . . . . . 206 __iar_Powl (library routine) . . . . . . . . . . . . . . . . . . . . . . . 118
DRX-2
Index
439
DRX-2
size_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 iso646.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 364
uintptr_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 istream (library header file). . . . . . . . . . . . . . . . . . . . . . . . 365
integers, implementation-defined behavior in C89 . . . . . . 417 italic style, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
integral promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 iterator (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 366
internal error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 I/O register. See SFR
__interrupt (extended keyword) . . . . . . . . . . . . . . . . . 65, 307 I/O, character-based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 339
interrupt functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 K
interrupt handler. See interrupt service routine keep_definition (pragma directive) . . . . . . . . . . . . . . 407, 421
interrupt service routine . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Kernighan & Ritchie function declarations . . . . . . . . . . . . 220
interrupt state, restoring . . . . . . . . . . . . . . . . . . . . . . . . . . 348 disallowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
interrupt vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
specifying with pragma directive . . . . . . . . . . . . . . . . . 339 extended, overview of . . . . . . . . . . . . . . . . . . . . . . . . . . 36
interrupt vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
in linker configuration file . . . . . . . . . . . . . . . . . . . . . . . 93
INITTAB segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
INTVEC segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
L
-l (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
start address for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 for creating skeleton code . . . . . . . . . . . . . . . . . . . . . . 153
interrupts labels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 assembler, making public . . . . . . . . . . . . . . . . . . . . . . . 269
during function execution . . . . . . . . . . . . . . . . . . . . . 65 __iar_program_start . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
processor state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 __program_start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
using with C++ destructors . . . . . . . . . . . . . . . . . . . . . 182 Labrosse, Jean J. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
intptr_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 __lac (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 345
__intrinsic (extended keyword). . . . . . . . . . . . . . . . . . . . . 307 language extensions
intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 enabling using pragma . . . . . . . . . . . . . . . . . . . . . . . . . 330
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 enabling (-e) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
intrinsics.h (header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 341 language overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
inttypes.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 364 language (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . 330
INTVEC (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 93, 385 _large_write (library function) . . . . . . . . . . . . . . . . . . . . . 143
intwri.c (library source code) . . . . . . . . . . . . . . . . . . . . . . 144 __las (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 346
invocation syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 __lat (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 346
__io (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . . 307 libraries
iomanip (library header file) . . . . . . . . . . . . . . . . . . . . . . . 365 reason for using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
ios (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 standard template library . . . . . . . . . . . . . . . . . . . . . . . 366
iosfwd (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 365 using a prebuilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
iostream (library header file). . . . . . . . . . . . . . . . . . . . . . . 365 using a prebuilt (CLIB) . . . . . . . . . . . . . . . . . . . . . . . . 141
DRX-2
Index
441
DRX-2
initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 allocating in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
low_level_init.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118, 145 dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
low-level processor operations . . . . . . . . . . . . . . . . . . . . . 168 external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275–276
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
M non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
RAM, saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
-m (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 releasing in C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
macros stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
embedded in #pragma optimize . . . . . . . . . . . . . . . . . . 333 saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
ERANGE (in errno.h) . . . . . . . . . . . . . . . . . . . . . 408, 422 used by global or static variables . . . . . . . . . . . . . . . . . . 53
inclusion of assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 memory consumption, reducing . . . . . . . . . . . . . . . . . . . . 143
NULL, implementation-defined behavior . . . . . . . . . . 409 memory management, type-safe . . . . . . . . . . . . . . . . . . . . 175
in C89 for CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 memory map
in C89 for DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 initializing SFRs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
substituted in #pragma directives . . . . . . . . . . . . . . . . . 168 linker configuration for . . . . . . . . . . . . . . . . . . . . . . . . . 87
variadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 memory models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
--macro_positions_in_diagnostics (compiler option) . . . . 258 identifying (__MEMORY_MODEL__) . . . . . . . . 356–357
main (function) specifying on command line (--memory_model) . . . . . 258
definition (C89) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 memory placement
implementation-defined behavior . . . . . . . . . . . . . . . . 400 of linker segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
malloc (library function) using pragma directive . . . . . . . . . . . . . . . . . . . . . . . . . . 56
See also heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 using type definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
implementation-defined behavior in C89 . . . . . . . 424, 427 memory segment. See segment
Mann, Bernhard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 memory types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
map (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
map, linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
math functions rounding mode, placing variables in . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
implementation-defined behavior . . . . . . . . . . . . . . . . . . . 412 pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
math functions (library functions) . . . . . . . . . . . . . . . . . . . 116 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
math.h (library header file) . . . . . . . . . . . . . . . . . . . . 364, 370 structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
max recursion depth (stack usage control directive) . . . . . 393 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
MB_LEN_MAX, implementation-defined behavior . . . . . 412 memory (pragma directive) . . . . . . . . . . . . . . . . . . . . 407, 422
_medium_write (library function) . . . . . . . . . . . . . . . . . . . 144 memory (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . 366
memcmp_G (library function) . . . . . . . . . . . . . . . . . . . . . 371 __MEMORY_MODEL__ (predefined symbol) . . . . 356–357
memcpy_G (library function) . . . . . . . . . . . . . . . . . . . . . . 371 --memory_model (compiler option) . . . . . . . . . . . . . . . . . 258
memcpy_P (library function) . . . . . . . . . . . . . . . . . . . . . . 371 __memory_of
memory operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 symbol used in library . . . . . . . . . . . . . . . . . . . . . . . . . 369
DRX-2
Index
443
DRX-2
--no_call_frame_info (compiler option) . . . . . . . . . . . . . . 260 offsetof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
--no_clustering (compiler option) . . . . . . . . . . . . . . . . . . . 260 old calling convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
--no_code_motion (compiler option) . . . . . . . . . . . . . . . . 261 --omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 266
--no_cross_call (compiler option) . . . . . . . . . . . . . . . . . . . 261 once (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 407, 422
--no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 261 --only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 266
__no_init (extended keyword) . . . . . . . . . . . . . . . . . 223, 311 operators
--no_inline (compiler option) . . . . . . . . . . . . . . . . . . . . . . 262 See also @ (operator)
__no_operation (intrinsic function) . . . . . . . . . . . . . . . . . . 347 for cast
--no_path_in_file_macros (compiler option). . . . . . . . . . . 262 in Extended EC++. . . . . . . . . . . . . . . . . . . . . . . . . . 176
no_pch (pragma directive) . . . . . . . . . . . . . . . . . . . . 407, 422 missing from Embedded C++ . . . . . . . . . . . . . . . . . 176
--no_rampd (compiler option) . . . . . . . . . . . . . . . . . . . . . . 262 for segment control . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
__no_runtime_init (extended keyword) . . . . . . . . . . . . . . 311 in inline assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
--no_size_constraints (compiler option) . . . . . . . . . . . . . . 262 new and delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
--no_static_destruction (compiler option) . . . . . . . . . . . . . 263 precision for 32-bit float . . . . . . . . . . . . . . . . . . . . . . . 286
--no_system_include (compiler option) . . . . . . . . . . . . . . 263 precision for 64-bit float . . . . . . . . . . . . . . . . . . . . . . . 286
--no_tbaa (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 263 sizeof, implementation-defined behavior . . . . . . . . . . . 413
--no_typedefs_in_diagnostics (compiler option) . . . . . . . . 264 variants for cast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
--no_ubrof_messages (compiler option) . . . . . . . . . . . . . . 264 _Pragma (preprocessor) . . . . . . . . . . . . . . . . . . . . . . . . 167
--no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 265 __ALIGNOF__, for alignment control. . . . . . . . . . . . . 170
--no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 265 __memory_of. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
--no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 265 ?, language extensions for . . . . . . . . . . . . . . . . . . . . . . 190
NULL @ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
implementation-defined behavior . . . . . . . . . . . . . . . . 409 optimization
implementation-defined behavior in C89 (CLIB) . . . . 425 clustering, disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
implementation-defined behavior in C89 (DLIB) . . . . 422 code motion, disabling . . . . . . . . . . . . . . . . . . . . . . . . . 261
in library header file (CLIB) . . . . . . . . . . . . . . . . . . . . 370 common sub-expression elimination, disabling . . . . . . 261
pointer constant, relaxation to Standard C . . . . . . . . . . 172 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
numeric conversion functions, disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
implementation-defined behavior . . . . . . . . . . . . . . . . . . . 414 function inlining, disabling (--no_inline) . . . . . . . . . . . 262
numeric (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 366 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
loop unrolling, disabling . . . . . . . . . . . . . . . . . . . . . . . 265
DRX-2
Index
P pragma directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
parameters basic_template_matching, using . . . . . . . . . . . . . . . . . 185
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 for absolute located data . . . . . . . . . . . . . . . . . . . . . . . 211
hidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 list of all recognized . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
non-scalar, avoiding . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 list of all recognized (C89). . . . . . . . . . . . . . . . . . . . . . 421
register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159–160 type_attribute, using. . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
rules for specifying a file or directory . . . . . . . . . . . . . 234 _Pragma (preprocessor operator) . . . . . . . . . . . . . . . . . . . 167
specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 precision arguments, library support for . . . . . . . . . . . . . . 144
stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159, 162 predefined symbols
typographic convention . . . . . . . . . . . . . . . . . . . . . . . . . 28 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
part number, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
--pending_instantiations (compiler option) . . . . . . . . . . . . 267 --predef_macro (compiler option) . . . . . . . . . . . . . . . . . . . 267
permanent registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 --preinclude (compiler option) . . . . . . . . . . . . . . . . . . . . . 268
perror (library function), --preprocess (compiler option) . . . . . . . . . . . . . . . . . . . . . 268
implementation-defined behavior in C89 . . . . . . . . . 424, 427 preprocessor
placement operator (_Pragma) . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
in named segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
of code and data, introduction to . . . . . . . . . . . . . . . . . . 74 preprocessor directives
plain char, implementation-defined behavior . . . . . . . . . . 402 comments at the end of . . . . . . . . . . . . . . . . . . . . . . . . 173
pointer types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 implementation-defined behavior . . . . . . . . . . . . . . . . 406
differences between . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 implementation-defined behavior in C89 . . . . . . . . . . . 420
mixing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 #pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
using the best . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 preprocessor extensions
pointers __VA_ARGS__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57, 289 #warning message . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
445
DRX-2
preprocessor symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
defining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Q
preserved registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 qualifiers
__PRETTY_FUNCTION__ (predefined symbol). . . . . . . 356 const and volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
primitives, for special functions . . . . . . . . . . . . . . . . . . . . . 64 implementation-defined behavior . . . . . . . . . . . . . . . . 406
print formatter, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . 114 implementation-defined behavior in C89 . . . . . . . . . . . 420
printf (library function) . . . . . . . . . . . . . . . . . . . . . . . 113, 143 queue (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 366
choosing formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
configuration symbols . . . . . . . . . . . . . . . . . . . . . . . . . 132
customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
implementation-defined behavior . . . . . . . . . . . . . . . . 411
R
-r (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
implementation-defined behavior in C89 . . . . . . . 424, 427
RAM
selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
initializers copied from ROM . . . . . . . . . . . . . . . . . . . . 46
__printf_args (pragma directive). . . . . . . . . . . . . . . . . . . . 334
saving memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
printf_P (library function) . . . . . . . . . . . . . . . . . . . . . . . . . 371
RAMPZ (register) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
printing characters, implementation-defined behavior . . . 413
range errors, in linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
processor configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
__raw (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 312
processor operations
read formatter, selecting . . . . . . . . . . . . . . . . . . . . . . 115, 145
accessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
reading guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
low-level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
reading, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
program entry label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
realloc (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
program termination, implementation-defined behavior . . 400
implementation-defined behavior in C89 . . . . . . . 424, 427
programming hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
See also heap
__program_start (label) . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
recursive functions
projects
avoiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
basic settings for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
storing data on stack . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
setting up for a library . . . . . . . . . . . . . . . . . . . . . . . . . 108
reentrancy (DLIB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
prototypes, enforcing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
reference information, typographic convention . . . . . . . . . . 28
ptrdiff_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . 289, 370
register keyword, implementation-defined behavior . . . . . 405
PUBLIC (assembler directive) . . . . . . . . . . . . . . . . . . . . . 269
register parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 159–160
publication date, of this guide . . . . . . . . . . . . . . . . . . . . . . . . 2
registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
--public_equ (compiler option) . . . . . . . . . . . . . . . . . . . . . 268
registers
public_equ (pragma directive) . . . . . . . . . . . . . . . . . . . . . 334
callee-save, stored on stack . . . . . . . . . . . . . . . . . . . . . . 60
putchar (library function) . . . . . . . . . . . . . . . . . . . . . . . . . 143
for function returns . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
putenv (library function), absent from DLIB . . . . . . . . . . 125
implementation-defined behavior in C89 . . . . . . . . . . . 419
puts_G (library function) . . . . . . . . . . . . . . . . . . . . . . . . . 371
in assembler-level routines. . . . . . . . . . . . . . . . . . . . . . 156
puts_P (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 372
preserved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
putw, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
__regvar (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 312
DRX-2
Index
447
DRX-2
located data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 signed long long (data type) . . . . . . . . . . . . . . . . . . . . . . . 282
naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 signed long (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
packing in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 signed short (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
placing in sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 signed values, avoiding . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
RSTACK --silent (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 272
reducing usage of . . . . . . . . . . . . . . . . . . . . . . . . . . 242 silent operation, specifying in compiler . . . . . . . . . . . . . . 272
using cross-call optimizations . . . . . . . . . . . . . . . . . 261 sin (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
specifying (--segment) . . . . . . . . . . . . . . . . . . . . . . . . . 271 sin (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 sinf (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
too long for address range . . . . . . . . . . . . . . . . . . . . . . . 96 sinl (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
too long, in linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 64-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 286
__segment_begin (extended operator) . . . . . . . . . . . . . . . 171 size optimization, specifying. . . . . . . . . . . . . . . . . . . . . . . 279
__segment_end (extended operator) . . . . . . . . . . . . . . . . . 171 size (in stack usage control file) . . . . . . . . . . . . . . . . . . . . 397
__segment_size (extended operator) . . . . . . . . . . . . . . . . . 171 size_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . 289, 370
semaphores skeleton code, creating for assembler language interface . 153
C example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 SLEEP (assembler instruction) . . . . . . . . . . . . . . . . . . . . . 349
operations on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 __sleep (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . 349
--separate_cluster_for_initialized_variables (compiler slist (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 _small_write (library function) . . . . . . . . . . . . . . . . . . . . . 144
set (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 source files, list all referred . . . . . . . . . . . . . . . . . . . . . . . . 255
setjmp.h (library header file) . . . . . . . . . . . . . . . . . . . 364, 370 space characters, implementation-defined behavior . . . . . 409
setlocale (library function) . . . . . . . . . . . . . . . . . . . . . . . . 135 special function registers (SFR) . . . . . . . . . . . . . . . . . . . . 222
settings, basic for project configuration . . . . . . . . . . . . . . . 48 special function types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
__set_interrupt_state (intrinsic function) . . . . . . . . . . . . . 348 speed optimization, specifying . . . . . . . . . . . . . . . . . . . . . 271
severity level, of diagnostic messages . . . . . . . . . . . . . . . . 231 --spmcr_address (compiler option) . . . . . . . . . . . . . . . . . . 273
specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 sprintf (library function) . . . . . . . . . . . . . . . . . . . . . . 113, 143
SFR choosing formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
accessing special function registers . . . . . . . . . . . . . . . 222 customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
declaring extern special function registers . . . . . . . . . . 211 sprintf_P (library function) . . . . . . . . . . . . . . . . . . . . . . . . 372
shared object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 sscanf (library function)
short (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 choosing formatter (CLIB). . . . . . . . . . . . . . . . . . . . . . 145
signal (library function) choosing formatter (DLIB) . . . . . . . . . . . . . . . . . . . . . 114
implementation-defined behavior . . . . . . . . . . . . . . . . 409 sscanf_P (library function) . . . . . . . . . . . . . . . . . . . . . . . . 372
implementation-defined behavior in C89 . . . . . . . . . . . 423 sstream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 365
signals, implementation-defined behavior. . . . . . . . . . . . . 400 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
at system startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 advantages and problems using . . . . . . . . . . . . . . . . . . . 61
signal.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 364 cleaning after function return . . . . . . . . . . . . . . . . . . . . 163
signed char (data type) . . . . . . . . . . . . . . . . . . . . . . . 282–283 contents of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
signed int (data type). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
DRX-2
Index
449
DRX-2
--strict (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 273 invoking compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
string (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 365 system function, implementation-defined behavior. . 401, 411
strings, supported in Embedded C++ . . . . . . . . . . . . . . . . 176 system locks interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
--string_literals_in_flash (compiler option). . . . . . . . . . . . 273 system startup
string.h (library header file) . . . . . . . . . . . . . . . . . . . 364, 370 CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
string.h, additional C functionality . . . . . . . . . . . . . . . . . . 368 customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
strlen_G (library function) . . . . . . . . . . . . . . . . . . . . . . . . 373 DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
strlen_P (library function) . . . . . . . . . . . . . . . . . . . . . . . . . 373 initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
strncasecmp, in string.h. . . . . . . . . . . . . . . . . . . . . . . . . . . 368 system termination
strncat_G (library function) . . . . . . . . . . . . . . . . . . . . . . . 374 CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
strncmp_G (library function) . . . . . . . . . . . . . . . . . . . . . . 374 C-SPY interface to . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
strncmp_P (library function) . . . . . . . . . . . . . . . . . . . . . . . 374 DLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
strncpy_G (library function) . . . . . . . . . . . . . . . . . . . . . . . 374 system (library function)
strncpy_P (library function) . . . . . . . . . . . . . . . . . . . . . . . 374 implementation-defined behavior in C89 . . . . . . . . . . . 428
strnlen, in string.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 implementation-defined behavior in C89 (DLIB) . . . . 425
strstream (library header file) . . . . . . . . . . . . . . . . . . . . . . 365 system_include (pragma directive) . . . . . . . . . . . . . . 407, 422
strtod (library function), configuring support for . . . . . . . 135 --system_include_dir (compiler option) . . . . . . . . . . . . . . 274
structure types
alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
layout of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 T
structures tan (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
anonymous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170, 208 tan (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
implementation-defined behavior . . . . . . . . . . . . . . . . 405 tanf (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
implementation-defined behavior in C89 . . . . . . . . . . . 419 tanl (library routine) . . . . . . . . . . . . . . . . . . . . . . . . . 117–118
placing in memory type . . . . . . . . . . . . . . . . . . . . . . . . . 57 __task (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 314
subnormal numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 technical support, IAR Systems . . . . . . . . . . . . . . . . . . . . 232
support, technical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 template support
Sutter, Herb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . 176, 183
__swap_nibbles (intrinsic function) . . . . . . . . . . . . . . . . . 349 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . 176
SWITCH (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388 Terminal I/O window
symbols making available (CLIB) . . . . . . . . . . . . . . . . . . . . . . . 147
anonymous, creating . . . . . . . . . . . . . . . . . . . . . . . . . . 167 not supported when . . . . . . . . . . . . . . . . . . . . . . . 107–108
including in output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 termination of system. See system termination
listing in linker map file . . . . . . . . . . . . . . . . . . . . . . . . . 96 termination status, implementation-defined behavior . . . . 411
overview of predefined . . . . . . . . . . . . . . . . . . . . . . . . . 37 terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
preprocessor, defining . . . . . . . . . . . . . . . . . . . . . . . . . 243 tgmath.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 364
syntax 32-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 286
command line options . . . . . . . . . . . . . . . . . . . . . . . . . 233 this (pointer) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
extended keywords . . . . . . . . . . . . . . . . . . . . 56, 296–298 class memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
DRX-2
Index
451
DRX-2
variables
auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 W
defined inside a function . . . . . . . . . . . . . . . . . . . . . . . . 60 #warning message (preprocessor extension) . . . . . . . . . . . 360
global warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . 53 classifying in compiler . . . . . . . . . . . . . . . . . . . . . . . . . 246
hints for choosing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 disabling in compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 265
local. See auto variables exit code in compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 278
non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 warnings icon, in this guide . . . . . . . . . . . . . . . . . . . . . . . . 29
omitting type info . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 warnings (pragma directive) . . . . . . . . . . . . . . . . . . . 407, 422
placing at absolute addresses . . . . . . . . . . . . . . . . . . . . 212 --warnings_affect_exit_code (compiler option) . . . . 230, 278
placing in named segments . . . . . . . . . . . . . . . . . . . . . 212 --warnings_are_errors (compiler option) . . . . . . . . . . . . . 278
static --warn_about_c_style_casts (compiler option) . . . . . . . . . 277
placement in memory . . . . . . . . . . . . . . . . . . . . . . . . 53 watchdog reset instruction . . . . . . . . . . . . . . . . . . . . . . . . 349
taking the address of . . . . . . . . . . . . . . . . . . . . . . . . 219 __watchdog_reset (intrinsic function) . . . . . . . . . . . . . . . . 349
variadic macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 wchar_t (data type), adding support for in C . . . . . . . . . . . 283
vector (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 65, 339 wchar.h (library header file) . . . . . . . . . . . . . . . . . . . 364, 367
vector (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 366 wctype.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 365
version weak (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 339
compiler subversion number . . . . . . . . . . . . . . . . . . . . 357 web sites, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
identifying C standard in use (__STDC_VERSION__) 357 white-space characters, implementation-defined behavior 400
of compiler (__VER__) . . . . . . . . . . . . . . . . . . . . . . . . 358 write formatter, selecting . . . . . . . . . . . . . . . . . . . . . 144–145
version number __write_array, in stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . 368
of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 __write_buffered (DLIB library function) . . . . . . . . . . . . 105
__version_1 (extended keyword) . . . . . . . . . . . . . . . . . . . 315
__VERSION_1_CALLS__ (predefined symbol) . . . . . . . 358
__version_2 (extended keyword) . . . . . . . . . . . . . . . . . . . 315
__version_4 (extended keyword) . . . . . . . . . . . . . . . . . . . 316
X
__x (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . . . 316
--version1_calls (compiler option) . . . . . . . . . . . . . . . . . . 276
__xch (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 349
--version2_calls (compiler option) . . . . . . . . . . . . . . . . . . 277
XLINK errors
--version (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 276
range error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
--vla (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
segment too long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
void, pointers to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
XLINK options
volatile
-O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
and const, declaring objects . . . . . . . . . . . . . . . . . . . . . 292
-y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
declaring objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
XLINK segment memory types . . . . . . . . . . . . . . . . . . . . . 72
protecting simultaneously accesses variables . . . . . . . . 221
XLINK. See linker
rules for access. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
--xmcra_address (compiler option) . . . . . . . . . . . . . . . . . . 278
__XMEGA_CORE__ (predefined symbol) . . . . . . . . . . . 359
__XMEGA_USB__ (predefined symbol) . . . . . . . . . . . . . 359
DRX-2
Index
453
DRX-2
__iar_cos_accuratef (library routine) . . . . . . . . . . . . . . . . 118 __iar_Sin_small (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_cos_accuratel (library routine) . . . . . . . . . . . . . . . . 118 __iar_sin_small (library routine). . . . . . . . . . . . . . . . . . . . 117
__iar_cos_small (library routine) . . . . . . . . . . . . . . . . . . . 117 __iar_Sin_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_cos_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117 __iar_sin_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_cos_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117 __iar_Sin_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117
__IAR_DLIB_PERTHREAD_INIT_SIZE (macro) . . . . . 139 __iar_sin_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117
__IAR_DLIB_PERTHREAD_SIZE (macro) . . . . . . . . . . 139 __IAR_SYSTEMS_ICC__ (predefined symbol) . . . . . . . 356
__IAR_DLIB_PERTHREAD_SYMBOL_OFFSET __iar_tan_accurate (library routine) . . . . . . . . . . . . . . . . . 118
(symbolptr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 __iar_tan_accuratef (library routine). . . . . . . . . . . . . . . . . 118
__iar_exp_small (library routine) . . . . . . . . . . . . . . . . . . . 117 __iar_tan_accuratel (library routine) . . . . . . . . . . . . . . . . . 118
__iar_exp_smallf (library routine) . . . . . . . . . . . . . . . . . . 117 __iar_tan_small (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_exp_smalll (library routine) . . . . . . . . . . . . . . . . . . 117 __iar_tan_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_log_small (library routine) . . . . . . . . . . . . . . . . . . . 117 __iar_tan_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117
__iar_log_smallf (library routine) . . . . . . . . . . . . . . . . . . . 117 __indirect_jump_to (intrinsic function) . . . . . . . . . . . . . . 345
__iar_log_smalll (library routine) . . . . . . . . . . . . . . . . . . . 117 __insert_opcode (intrinsic function) . . . . . . . . . . . . . . . . . 345
__iar_log10_small (library routine) . . . . . . . . . . . . . . . . . 117 __interrupt (extended keyword) . . . . . . . . . . . . . . . . . 65, 307
__iar_log10_smallf (library routine) . . . . . . . . . . . . . . . . . 117 using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 339
__iar_log10_smalll (library routine) . . . . . . . . . . . . . . . . . 117 __intrinsic (extended keyword). . . . . . . . . . . . . . . . . . . . . 307
__iar_Pow (library routine) . . . . . . . . . . . . . . . . . . . . . . . . 118 __io (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . . 307
__iar_Powf (library routine) . . . . . . . . . . . . . . . . . . . . . . . 118 __lac (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 345
__iar_Powl (library routine) . . . . . . . . . . . . . . . . . . . . . . . 118 __las (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 346
__iar_Pow_accurate (library routine) . . . . . . . . . . . . . . . . 118 __lat (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . . 346
__iar_pow_accurate (library routine) . . . . . . . . . . . . . . . . 118 __LINE__ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 356
__iar_Pow_accuratef (library routine) . . . . . . . . . . . . . . . 118 __load_program_memory (intrinsic function) . . . . . . . . . 346
__iar_pow_accuratef (library routine). . . . . . . . . . . . . . . . 118 __low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
__iar_Pow_accuratel (library routine). . . . . . . . . . . . . . . . 118 initialization phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
__iar_pow_accuratel (library routine) . . . . . . . . . . . . . . . . 118 __low_level_init, customizing . . . . . . . . . . . . . . . . . . . . . 122
__iar_pow_small (library routine) . . . . . . . . . . . . . . . . . . 117 __MEMORY_MODEL__ (predefined symbol) . . . . 356–357
__iar_pow_smallf (library routine) . . . . . . . . . . . . . . . . . . 117 __memory_of
__iar_pow_smalll (library routine) . . . . . . . . . . . . . . . . . . 117 operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
__iar_program_start (label). . . . . . . . . . . . . . . . . . . . . . . . 119 symbol used in library . . . . . . . . . . . . . . . . . . . . . . . . . 369
__iar_Sin (library routine) . . . . . . . . . . . . . . . . . . . . 117–118 __monitor (extended keyword) . . . . . . . . . . . . . . . . . . . . . 308
__iar_Sinf (library routine) . . . . . . . . . . . . . . . . . . . . 117–118 __multiply_signed (intrinsic function) . . . . . . . . . . . . . . . 346
__iar_Sinl (library routine) . . . . . . . . . . . . . . . . . . . . 117–118 __multiply_signed_with_unsigned (intrinsic function) . . . 346
__iar_Sin_accurate (library routine) . . . . . . . . . . . . . . . . . 118 __multiply_unsigned (intrinsic function) . . . . . . . . . . . . . 346
__iar_sin_accurate (library routine) . . . . . . . . . . . . . . . . . 118 __near (extended keyword) . . . . . . . . . . . . . . . . . . . . 288, 308
__iar_Sin_accuratef (library routine) . . . . . . . . . . . . . . . . 118 __nearfunc (extended keyword) . . . . . . . . . . . . . . . . . . . . 309
__iar_sin_accuratef (library routine) . . . . . . . . . . . . . . . . . 118 __nearfunc (function pointer) . . . . . . . . . . . . . . . . . . . . . . 287
__iar_Sin_accuratel (library routine) . . . . . . . . . . . . . . . . 118 __nested (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 309
__iar_sin_accuratel (library routine) . . . . . . . . . . . . . . . . . 118
DRX-2
Index
455
DRX-2
--diag_suppress (compiler option) . . . . . . . . . . . . . . . . . . 246 --no_inline (compiler option) . . . . . . . . . . . . . . . . . . . . . . 262
--diag_warning (compiler option) . . . . . . . . . . . . . . . . . . . 246 --no_path_in_file_macros (compiler option). . . . . . . . . . . 262
--disable_all_program_memory_load_instructions (compiler --no_rampd (compiler option) . . . . . . . . . . . . . . . . . . . . . . 262
option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 --no_size_constraints (compiler option) . . . . . . . . . . . . . . 262
--disable_direct_mode (compiler option) . . . . . . . . . . . . . 247 --no_static_destruction (compiler option) . . . . . . . . . . . . . 263
--disable_library_knowledge (compiler option) . . . . . . . . 247 --no_system_include (compiler option) . . . . . . . . . . . . . . 263
--disable_mul (compiler option) . . . . . . . . . . . . . . . . . . . . 247 --no_typedefs_in_diagnostics (compiler option) . . . . . . . . 264
--disable_spm (compiler option) . . . . . . . . . . . . . . . . . . . . 248 --no_ubrof_messages (compiler option) . . . . . . . . . . . . . . 264
--discard_unused_publics (compiler option) . . . . . . . . . . . 248 --no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 265
--dlib (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . 248 --no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 265
--dlib_config (compiler option). . . . . . . . . . . . . . . . . . . . . 249 --no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 265
--do_cross_call (compiler option) . . . . . . . . . . . . . . . . . . . 250 --omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 266
--ec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 250 --only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 266
--eecr_address (compiler option) . . . . . . . . . . . . . . . . . . . 251 --output (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . 267
--eec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 251 --pending_instantiations (compiler option) . . . . . . . . . . . . 267
--eeprom_size (compiler option) . . . . . . . . . . . . . . . . . . . . 251 --predef_macro (compiler option) . . . . . . . . . . . . . . . . . . . 267
--enable_external_bus (compiler option) . . . . . . . . . . . . . 252 --preinclude (compiler option) . . . . . . . . . . . . . . . . . . . . . 268
--enable_multibytes (compiler option) . . . . . . . . . . . . . . . 252 --preprocess (compiler option) . . . . . . . . . . . . . . . . . . . . . 268
--enable_restrict (compiler option) . . . . . . . . . . . . . . . . . . 253 --relaxed_fp (compiler option) . . . . . . . . . . . . . . . . . . . . . 269
--enhanced_core (compiler option) . . . . . . . . . . . . . . . . . . 253 --remarks (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 269
--error_limit (compiler option) . . . . . . . . . . . . . . . . . . . . . 253 --require_prototypes (compiler option) . . . . . . . . . . . . . . . 270
--force_switch_type (compiler option) . . . . . . . . . . . . . . . 254 --root_variables (compiler option) . . . . . . . . . . . . . . . . . . 270
--guard_calls (compiler option). . . . . . . . . . . . . . . . . . . . . 255 --segment (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 271
--header_context (compiler option) . . . . . . . . . . . . . . . . . . 255 --separate_cluster_for_initialized_variables (compiler
--initializers_in_flash (compiler option) . . . . . . . . . . 256, 275 option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
--library_module (compiler option) . . . . . . . . . . . . . . . . . 257 --silent (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 272
--lock_regs (compiler option) . . . . . . . . . . . . . . . . . . . . . . 258 --spmcr_address (compiler option) . . . . . . . . . . . . . . . . . . 273
--macro_positions_in_diagnostics (compiler option) . . . . 258 --strict (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 273
--memory_model (compiler option) . . . . . . . . . . . . . . . . . 258 --string_literals_in_flash (compiler option). . . . . . . . . . . . 273
--mfc (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . 259 --system_include_dir (compiler option) . . . . . . . . . . . . . . 274
--misrac (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 237 --use_c++_inline (compiler option) . . . . . . . . . . . . . . . . . 274
--misrac_verbose (compiler option) . . . . . . . . . . . . . . . . . 237 --version (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 276
--misrac1998 (compiler option) . . . . . . . . . . . . . . . . . . . . 237 --version1_calls (compiler option) . . . . . . . . . . . . . . . . . . 276
--misrac2004 (compiler option) . . . . . . . . . . . . . . . . . . . . 237 --version2_calls (compiler option) . . . . . . . . . . . . . . . . . . 277
--module_name (compiler option) . . . . . . . . . . . . . . . . . . 260 --vla (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
--no_call_frame_info (compiler option) . . . . . . . . . . . . . . 260 --warnings_affect_exit_code (compiler option) . . . . 230, 278
--no_clustering (compiler option) . . . . . . . . . . . . . . . . . . . 260 --warnings_are_errors (compiler option) . . . . . . . . . . . . . 278
--no_code_motion (compiler option) . . . . . . . . . . . . . . . . 261 --warn_about_c_style_casts (compiler option) . . . . . . . . . 277
--no_cross_call (compiler option) . . . . . . . . . . . . . . . . . . . 261 --xmcra_address (compiler option) . . . . . . . . . . . . . . . . . . 278
--no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 261 --zero_register (compiler option) . . . . . . . . . . . . . . . . . . . 280
DRX-2
Index
Numerics
32-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 286
--64bit_doubles (compiler option) . . . . . . . . . . . . . . . . . . 240
--64k_flash (compiler option) . . . . . . . . . . . . . . . . . . . . . . 240
64-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 286
457
DRX-2