(IAR) .ARM IAR C, C++ Compiler - Reference Guide
(IAR) .ARM IAR C, C++ Compiler - Reference Guide
Reference Guide
COPYRIGHT NOTICE
Copyright 19992004 IAR Systems. All rights reserved. No part of this document may be reproduced without the prior written consent of IAR Systems. 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 Embedded Workbench, IAR visualSTATE, and IAR MakeApp are registered trademarks owned by IAR Systems. C-SPY is a trademark registered in the European Union and Japan by IAR Systems. IAR, IAR XLINK Linker, IAR XAR Library Builder, and IAR XLIB Librarian are trademarks owned by IAR Systems. ARM and Thumb are registered trademarks of Advanced RISC Machines Ltd. Microsoft and Windows are registered trademarks of Microsoft Corporation. Intel and Pentium are registered trademarks and XScale a trademark of Intel Corporation. All other product names are trademarks or registered trademarks of their respective owners.
EDITION NOTICE
Eleventh edition: December 2004 Part number: CARM-11 This guide applies to version 4.x of ARM IAR Embedded Workbench.
Brief contents
Tables
..................................................................................................................... xiii .................................................................................................................... xv ......................................................... 1
Preface
.................................................................................................... 3
...................................................................................................... 11
................................................................... 69
............................................................................................................ 85 ........................................ 91
Extended keywords
Pragma directives ............................................................................................ 157 The preprocessor ........................................................................................... 169 Intrinsic functions Library functions
........................................................................................... 177
Implementation-defined behavior
iii
............................................................................. 201
......................................................................................................... 211
..................................................................................................................... 213
iv
Reference Guide
Contents
Tables
..................................................................................................................... xiii .................................................................................................................... xv
Preface
Who should read this guide ............................................................... xv How to use this guide .......................................................................... xv What this guide contains .................................................................... xvi Other documentation .........................................................................xvii
Further reading .................................................................................xvii
......................................................... 1
.................................................................................................... 3
Data storage
...................................................................................................... 11
Introduction .............................................................................................. 11 The stack and auto variables ............................................................. 11 Dynamic memory on the heap ........................................................ 13
Functions
............................................................................................................. 15
ARM and Thumb code ........................................................................ 15 Keywords for functions ........................................................................ 15 Execution in RAM ................................................................................... 16 Interrupt functions ................................................................................. 17
Interrupts and fast interrupts .............................................................. 17 Nested interrupts ................................................................................ 18 Software interrupts ............................................................................. 19 Installing interrupt functions .............................................................. 20 Interrupt operations ............................................................................ 20 Monitor functions ............................................................................... 21 C++ and special function types ......................................................... 22
.................................................................................... 25
vi
Reference Guide
Contents
............................................................... 39
Overriding library modules ................................................................ 47 Building and using a customized library ....................................... 49
Setting up a library project ................................................................. 49 Modifying the library functionality .................................................... 49 Using a customized library ................................................................ 50
vii
Environment interaction ..................................................................... 59 Signal and raise ........................................................................................ 60 Time ............................................................................................................. 61 Strtod ........................................................................................................... 61 Assert ........................................................................................................... 61 C-SPY Debugger runtime interface .............................................. 62
Low-level debugger runtime interface ............................................... 62 The debugger terminal I/O window ................................................... 63
................................................................... 69
viii
Reference Guide
Contents
Using C++
............................................................................................................ 85
Overview .................................................................................................... 85
Standard Embedded C++ ................................................................... 85 Extended Embedded C++ .................................................................. 86 Enabling C++ support ........................................................................ 86
........................................ 91
ix
Segment reference
......................................................................................... 117
Compiler options
........................................................................................... 125
Reference Guide
Contents
Extended keywords
....................................................................................... 151
Using extended keywords ................................................................. 151 Summary of extended keywords ................................................... 151 Descriptions of extended keywords ............................................. 152
Intrinsic functions
........................................................................................... 177
Intrinsic functions summary ............................................................ 177 Descriptions of intrinsic functions ................................................. 178
Library functions
............................................................................................. 183
Implementation-defined behavior
.......................................................... 189
xi
Characters ......................................................................................... 190 Integers ............................................................................................. 192 Floating point ................................................................................... 192 Arrays and pointers .......................................................................... 193 Registers ........................................................................................... 193 Structures, unions, enumerations, and bitfields ............................... 193 Qualifiers .......................................................................................... 194 Declarators ....................................................................................... 194 Statements ........................................................................................ 194 Preprocessing directives ................................................................... 194 IAR DLIB Library functions ............................................................ 196
............................................................................. 201
Why should language extensions be used? ................................ 201 Descriptions of language extensions ............................................ 201
Diagnostics
......................................................................................................... 211
Index
..................................................................................................................... 213
xii
Reference Guide
Tables
1: Typographic conventions used in this guide ...................................................... xviii 2: Command line options for specifying library and dependency files ....................... 8 3: XLINK segment memory types ............................................................................ 26 4: Memory layout of a target system (example) ....................................................... 27 5: Segment name suffixes ......................................................................................... 30 6: Exception stacks .................................................................................................... 32 7: Segment groups ..................................................................................................... 34 8: Library configurations ........................................................................................... 41 9: Prebuilt libraries .................................................................................................... 42 10: Customizable items ............................................................................................. 44 11: Formatters for printf ............................................................................................ 46 12: Formatters for scanf ............................................................................................ 47 13: Descriptions of printf configuration symbols ..................................................... 55 14: Descriptions of scanf configuration symbols ...................................................... 56 15: Low-level I/O files .............................................................................................. 57 16: Functions with special meanings when linked with debug info ......................... 62 17: Example of runtime model attributes .................................................................. 64 18: Predefined runtime model attributes ................................................................... 65 19: Registers used for passing parameters ................................................................ 77 20: VFP registers used for passing parameters in non-interworking mode .............. 78 21: Registers used for returning values ..................................................................... 79 22: VFP registers used for returning values in non-interworking mode ................... 79 23: Call frame information resources defined in a names block ............................... 83 24: Compiler optimization levels .............................................................................. 92 25: Integer types ...................................................................................................... 108 26: Floating-point types .......................................................................................... 110 27: Segment summary ............................................................................................. 117 28: Environment variables ...................................................................................... 127 29: Error return codes .............................................................................................. 127 30: Compiler options summary ............................................................................... 127 31: Generating a list of dependencies (--dependencies) .......................................... 132
xiii
32: Generating a compiler list file (-l) ..................................................................... 139 33: Directing preprocessor output to file (--preprocess) ......................................... 146 34: Specifying speed optimization (-s) .................................................................... 147 35: Specifying size optimization (-z) ...................................................................... 149 36: Extended keywords summary ........................................................................... 151 37: Pragma directives summary .............................................................................. 157 38: Predefined symbols summary ........................................................................... 170 39: Predefined symbols for inspecting the CPU mode ........................................... 172 40: Values for specifying different CPU cores in __TID__ ................................... 174 41: Intrinsic functions summary .............................................................................. 177 42: Traditional standard C header filesDLIB ..................................................... 185 43: Embedded C++ header files .............................................................................. 186 44: Additional Embedded C++ header filesDLIB ............................................... 186 45: Standard template library header files ............................................................... 186 46: New standard C header filesDLIB ............................................................... 187 47: Message returned by strerror()IAR DLIB library ......................................... 199
xiv
Reference Guide
Preface
Welcome to the ARM IAR C/C++ Compiler Reference Guide. The purpose of this guide is to provide you with detailed reference information that can help you to use the ARM IAR C/C++ 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.
The architecture and instruction set of the ARM core. Refer to the documentation from Advanced RISC Machines Ltd for information about the ARM core The C or C++ programming language Application development for embedded systems The operating system of your host machine.
xv
Getting started gives the information you need to get started using the ARM IAR C/C++ Compiler for efficiently developing your application. Data storage describes how data can be stored in memory. Functions describes the different ways code can be generated, and introduces the concept of function type attributes, such as interrupt functions. Placing code and data describes the concept of segments, introduces the linker command file, and describes how code and data are placed in memory. The DLIB runtime environment gives an overview of the runtime libraries and how they can be customized. The chapter also describes system initialization and introduces the cstartup file. Assembler language interface contains information required when parts of an application are written in assembler language. This includes the calling convention. Using C++ gives an overview of the two levels of C++ support: The industry-standard EC++ and IAR Extended EC++. Efficient coding for embedded applications gives hints about how to write code that compiles to efficient code for an embedded application.
Data representation describes the available data types, pointers, and structure types. It also describes the concepts of attributes. Segment reference gives reference information about the compilers use of segments. Compiler options explains how to set the compiler options, gives a summary of the options, and contains detailed reference information for each compiler option. Extended keywords gives reference information about each of the ARM-specific keywords that are extensions to the standard C language. Pragma directives gives reference information about the pragma directives. The preprocessor gives a brief overview of the preprocessor, including reference information about the different preprocessor directives, symbols, and other related information. Intrinsic functions gives reference information about the functions that can be used for accessing ARM-specific low-level features. Library functions gives an introduction to the C or C++ library functions, and summarizes the header files. Implementation-defined behavior describes how the ARM IAR C/C++ Compiler handles the implementation-defined areas of the C language standard.
xvi
Reference Guide
Preface
IAR language extensions describes the IAR extensions to the ISO/ANSI standard for the C programming language. Diagnostics describes how the compilers diagnostic system works.
Other documentation
The complete set of IAR Systems development tools for the ARM core is described in a series of guides. For information about:
Using the IAR Embedded Workbench IDE with the IAR C-SPY Debugger, refer to the ARM IAR Embedded Workbench IDE User Guide Programming for the ARM IAR Assembler, refer to the ARM IAR Assembler Reference Guide Using the IAR XLINK Linker, the IAR XAR Library Builder, and the IAR XLIB Librarian, refer to the IAR Linker and Library Tools Reference Guide Using the IAR DLIB Library, refer to the online help system, available from the ARM IAR Embedded Workbench IDE Help menu ARM IAR Embedded Workbench Migration Guide gives hints for porting application code and projects to this product version.
All of these guides are delivered in PDF or HTML format on the installation media. Some of them are also delivered as printed books.
FURTHER READING
The following books may be of interest to you when using the IAR Systems development tools:
Furber, Steve, ARM System-on-Chip Architecture. Addison-Wesley. Sloss, Andrew N. et al, ARM System Developers Guide: Designing and Optimizing System Software. Morgan Kaufmann. ARM Architecture Reference Manual. ARM Limited. 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. Kernighan, Brian W. and Dennis M. Ritchie. The C Programming Language. Prentice Hall. [The later editions describe the ANSI C standard.] Labrosse, Jean J. Embedded Systems Building Blocks: Complete and Ready-To-Use Modules in C. R&D Books. Lippman, Stanley B. and Josee Lajoie. C++ Primer. Addison-Wesley. Mann, Bernhard. C fr Mikrocontroller. Franzis-Verlag. [Written in German.] Stroustrup, Bjarne. The C++ Programming Language. Addison-Wesley.
xvii
Document conventions
The Advanced RISC Machines Ltd website, www.arm.com, contains information and news about the ARM core. The IAR website, www.iar.com, holds application notes and other product information. Finally, the Embedded C++ Technical Committee website, www.caravan.net/ec2plus, contains information about the Embedded C++ standard.
Document conventions
When, in this text, we refer to the programming language C, the text also applies to C++, unless otherwise stated.
TYPOGRAPHIC CONVENTIONS
This guide uses the following typographic conventions:
Style Used for
Text that you enter or that appears on the screen. A label representing the actual value you should enter as part of a command. An optional part of a command. Alternatives in a command. Names of menus, menu commands, buttons, and dialog boxes that appear on the screen. A cross-reference within this guide or to another guide. Identifies instructions specific to the IAR Embedded Workbench interface. Identifies instructions specific to the command line interface. Identifies helpful tips and programming hints.
xviii
Reference Guide
Getting started Data storage Functions Placing code and data The DLIB runtime environment Assembler language interface Using C++ Efficient coding for embedded applications.
Getting started
This chapter gives the information you need to get started using the ARM IAR C/C++ Compiler for efficiently developing your application. First you will get an overview of the supported programming languages, followed by a description of the steps involved for compiling and linking an application. Next, the compiler is introduced. You will get an overview of the basic settings needed for a project setup, including an overview of the techniques that enable applications to take full advantage of the ARM core. In the following chapters, these techniques will be studied in more detail.
C, the most widely used high-level programming language used in the embedded systems industry. Using the ARM IAR C/C++ Compiler, you can build freestanding applications that follow the standard ISO 9899:1990. This standard is commonly known as ANSI C. C++, a modern object-oriented programming language with a full-featured library well suited for modular programming. IAR Systems supports two levels of the C++ language:
Embedded C++ (EC++), a proper subset of the C++ programming standard, which is intended for embedded systems programming. It is defined by an industry consortium, the Embedded C++ Technical committee. See the chapter Using C++. Extended EC++, with additional features such as full template support, namespace support, the new cast operators, as well as the Standard Template Library (STL).
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 deviations from the standard. It is also possible to implement parts of the application, or the whole application, in assembler language. See the ARM IAR Assembler Reference Guide.
For more information about the Embedded C++ language and IAR Extended Embedded EC++, see the chapter Using C++.
COMPILING
In the command line interface, the following line compiles the source file myfile.c into the object file myfile.r79 using the default settings:
iccarm myfile.c
In addition, you need to specify some critical options, see Basic settings for project configuration, page 5.
LINKING
The IAR XLINK Linker is used for building the final application. Normally, XLINK requires the following information as input:
A number of object files and possibly certain libraries The standard library containing the runtime environment and the standard language functions A program start label A linker command file that describes the memory layout of the target system Information about the output format.
On the command line, the following line can be used for starting XLINK:
xlink myfile.r79 myfile2.r79 -s __program_start -f lnkarm.xcl dl4tpann18n.r79 -o aout.a79 -Felf/dwarf
Reference Guide
Getting started
In this example, myfile.r79 and myfile2.r79 are object files, lnkarm.xcl is the linker command file, and dl4tpann18n.r79 is the runtime library. The option -s specifies the label where the application starts. The option -o specifies the name of the output file, and the option -F must be used for specifying output files. The IAR XLINK Linker produces output after your specifications. Choose the output format that suits your purpose. You might want to load the output to a debuggerwhich means that you need output with debug information. Alternatively, you might want to load the output to a PROM programmerin which case you need output without debug information, such as Intel-hex or Motorola S-records.
Processor variant CPU mode Interworking Floating-point arithmetic Byte order Optimization settings Runtime library.
In addition to these settings, there are many other options and settings available for fine-tuning the result even further. See the chapter Compiler options for a list of all available options.
PROCESSOR VARIANT
The ARM IAR C/C++ Compiler supports several different ARM cores and derivatives based on these cores. All supported cores support Thumb instructions and 64-bit multiply instructions. The object code that the compiler generates is not binary compatible. Therefore it is crucial to specify a processor option to the compiler. The default core is ARM7TDMI. See the ARM IAR Embedded Workbench IDE User Guide for information about setting the Processsor variant option in the IAR Embedded Workbench. Use the --cpu option to specify the ARM core; see the chapter Compiler options for syntax information.
ARM7TDMI ARM7TDMI-S ARM710T ARM720T ARM740T ARM9TDMI ARM920T ARM922T ARM940T ARM9E ARM9E-S ARM926EJ-S ARM946E-S ARM966E-S ARM968E-S ARM10E ARM1020E ARM1022E ARM1026EJ-S XScale XScale-IR7.
CPU MODE
The ARM IAR C/C++ Compiler supports two CPU modes: ARM and Thumb. All functions and function pointers will compile in the mode that you specify, except those explicitly declared __arm or __thumb. See the ARM IAR Embedded Workbench IDE User Guide for information about setting the Processor variant or Chip option in the IAR Embedded Workbench. Use the --cpu_mode option to specify the CPU mode for your project; see --cpu_mode, page 130, for syntax information.
INTERWORKING
When code is compiled with the --interwork option, ARM and Thumb code can be freely mixed. Interworking library functions can be called from both ARM and Thumb code. The interworking libraries are slightly lareger than non-interworking libraries. See the ARM IAR Embedded Workbench IDE User Guide for information about setting the Generate interwork code option in the IAR Embedded Workbench.
Reference Guide
Getting started
Use the --interwork option to specify interworking capabilities for your project; see --interwork, page 139, for syntax information.
BYTE ORDER
The ARM IAR C/EC++ Compiler supports the big-endian and little-endian byte order. All user and library modules in your application must use the same byte order. See the ARM IAR Embedded Workbench IDE User Guide for information about setting the Endian mode option in the IAR Embedded Workbench. Use the --endian option to specify the byte order for your project; see --endian, page 136, for syntax information.
RUNTIME ENVIRONMENT
To create the required runtime environment you should choose a runtime library and set library options. You may also need to override certain library modules with your own customized versions. The runtime library provided is the IAR DLIB Library, which supports ISO/ANSI C and C++. This library also supports floating-point numbers in IEEE 754 format and it can be configured to include different levels of support for locale, file descriptors, multibytes, et cetera. The runtime library you choose can be one of the prebuilt libraries, or a library that you have customized and built yourself. The IAR Embedded Workbench IDE provides a library project template that you can use for building your own library version. This gives you full control of the runtime environment. If your project only contains assembler source code, there is no need to choose a runtime library. For detailed information about the runtime environment, see the chapter The DLIB runtime environment. The way you set up a runtime environment and locate all the related files differs depending on which build interface you are usingthe IAR Embedded Workbench IDE or the command line.
-I\arm\inc libraryfile.r79
Table 2: Command line options for specifying library and dependency files
Reference Guide
Getting started
Command line
Description
-dlib_config C:\...\configfile.h
Table 2: Command line options for specifying library and dependency files (Continued)
For a list of all prebuilt library object files for the IAR DLIB Library, see Table 9, Prebuilt libraries, page 42. The table also shows how the object files correspond to the dependent project options, and the corresponding configuration files. Make sure to use the object file that matches your other project options.
The formatters used by the functions printf, scanf, and their variants, see Choosing printf formatter, page 45 and Choosing scanf formatter, page 46, respectively. The size of the stack and the heap, see The stack, page 31, and The heap, page 32, respectively.
EXTENDED KEYWORDS
The ARM IAR C/C++ Compiler provides a set of keywords that can be used for configuring how the code is generated. For example, there are keywords for declaring special function types. By default, language extensions are enabled in the IAR Embedded Workbench. 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 135 for additional information. For detailed descriptions of the extended keywords, see the chapter Extended keywords.
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 ARM IAR C/C++ Compiler. They are consistent with ISO/ANSI C, and are very useful when you want to make sure that the source code is portable. For detailed descriptions of the pragma directives, see the chapter Pragma directives.
PREDEFINED SYMBOLS
With the predefined preprocessor symbols, you can inspect your compile-time environment, for example the CPU mode and time of compilation. For detailed descriptions of the predefined symbols, see the chapter The preprocessor.
10
Reference Guide
Data storage
This chapter gives a brief introduction to the memory layout of the ARM core and the fundamental ways data can be stored in memory: on the stack, in static (global) memory, or in heap memory.
Introduction
The ARM core can address 4 Gbytes of continuous memory, ranging from 0x00000000 to 0xFFFFFFFF. Different types of physical memory can be placed in the memory range. A typical application will have both read-only memory (ROM) and read/write memory (RAM). In addition, some parts of the memory range contain processor control registers and peripheral units. In a typical application, data can be stored in memory in three different ways:
On the stack. This is memory space that can be used by a function as long as it is executing. When the function returns to its caller, the memory space is no longer valid. Static memory. This kind of memory is allocated once and for all; it remains valid through the entire execution of the application. Variables that are either global or declared static are placed in this type of memory. The word static in this context means that the amount of memory allocated for this type of variable does not change while the application is running. The ARM core has one single address space and the compiler supports full memory addressing. On the heap. Once memory has been allocated on the heap, it remains valid until it is explicitly released back to the system by the application. This type of memory is useful when the number of objects is not known until the application executes. Note that there are potential risks connected with using the heap in systems with a limited amount of memory, or systems that are expected to run for a long time.
11
Local variables and parameters not stored in registers Temporary results of expressions The return value of a function (unless it is passed in registers) Processor state during interrupts Processor registers that should be restored before the function returns (callee-save registers).
The stack is a fixed block of memory, divided into two parts. The first part contains allocated memory used by the function that called the current function, and the function that called it, etc. The second part contains free memory that can be allocated. The borderline between the two areas is called the top of stack and is represented by the stack pointer, which is a dedicated processor register. Memory is allocated on the stack by moving the stack pointer. A function should never refer to the memory in the area of the stack that contains free memory. The reason is that if an interrupt occurs, the called interrupt function can allocate, modify, andof coursedeallocate memory on the stack.
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 itselfa so-called a recursive functionand 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 has returned. 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 ... return &x; }
12
Reference Guide
Data storage
Another problem is the risk of running out of stack. 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 functionsfunctions that call themselves either directly or indirectlyare used.
Potential problems
Applications that are using heap-allocated objects must be designed very carefully, 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 because your application simply uses too much memory. It can also become full if memory that no longer is in use has not been 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 there is no piece of free memory that 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. Hence, applications that are designed to run for a long time should try to avoid using memory allocated on the heap.
13
14
Reference Guide
Functions
This chapter contains information about functions. First, you get an overview of ARM and Thumb code generation. Execution in RAM and the special function types interrupt, software interrupt, fast interrupts, and monitor are described, including how to declare C++ member functions by using special function types. Then, it is shown how to place functions into named segments. The last section describes the function directives.
Keywords that control the type of the functions. Keywords of this group must be specified both when the function is declared and when it is defined: __arm, __fiq, __interwork, __irq, __monitor, __swi, and __thumb. Keywords that only control the defined function: __root and __ramfunc.
15
Execution in RAM
For reference information about these keywords, see the chapter Extended keywords in Part 2. Compiler reference.
Syntax
The extended keywords are specified before the return type, for example:
__irq __arm void alpha(void);
The keywords that are type attributes must be specified both when they are defined and in the declaration. Object attributes only have to be specified when they are defined because they do not affect the way an object or function is used.
Execution in RAM
The __ramfunc keyword makes a function execute in RAM. The function is copied from ROM to RAM by cstartup, see System startup and termination, page 51. The keyword is specified before the return type:
__ramfunc void foo(void);
If a function declared __ramfunc tries to access ROM, the compiler will issue a warning. If the whole memory area used for code and constants is disabledfor example, when the whole flash memory is being erasedonly functions and data stored in RAM may be used. Interrupts must be disabled unless the interrupt vector and the interrupt service routines are also stored in RAM. String literals and other constants can be avoided by using initialized variables. For example, the following lines:
const int myc[] = { 10, 20 }; msg("Hello"); may be rewritten to: static int myc[] = { 10, 20 }; static char hello[] = "Hello"; msg(hello); // // // // // // // // myc initializer in DATA_C (ROM) String literal in DATA_C (ROM) Initialized by cstartup Initialized by cstartup hello stored in DATA_I (RAM)
If the option --segment is used for renaming segments, the new segments for storing __ramfunc functions must be declared in the linker command file. The compiler option --segment code=MYSEG is used in this example.
16
Reference Guide
Functions
All functions without attributes are linked in segment MYSEG_T. Functions declared __ramfunc are linked in segment MYSEG_I, with initializers in segment MYSEG_ID. The following segment options need to be added in the linker command file:
-Z(CODE)MYSEG=ROMSTART-ROMEND -Z(DATA)MYSEG_I=RAMSTART-RAMEND // // // -Z(CONST)MYSEG_ID=ROMSTART-ROMEND // // -QMYSEG_I=MYSEG_ID // // // Ordinary functions Functions stored in RAM. Initializer for MYSEG_I. Instruct XLINK to place all data content of MYSEG_I in MYSEG_ID
The contents of MYSEG_ID is copied to MYSEG_I by the function __segment_init, called by cstartup; for details, see Segment_init.c and Segment_init.h in the arm\src\lib directory.
Interrupt functions
In embedded systems, the use of interrupts is a method of detecting external events immediately, for example a button being pressed. In general, when an interrupt occurs in the code, the processor simply stops executing the code it runs and starts executing an interrupt routine instead. The processor state prior to the interrupt is stored so that it can be restored at the end of the interrupt routine. This enables the execution of the original code to continue. The ARM IAR C/C++ Compiler supports interrupts, software interrupts, and fast interrupts. This allows an application to take full advantage of these powerful ARM features without forcing you to implement anything in assembler language. All interrupt functions must be compiled in ARM mode; if you are using Thumb mode, use the __arm extended keyword or the #pragma type_attribute=__arm directive to alter the default behavior.
An interrupt function is declared by use of the __irq extended keyword or the #pragma type_attribute=__irq directive. For syntax information, see __irq, page 153, and #pragma type_attribute, page 166, respectively. A fast interrupt function is declared by use of the __fiq extended keyword or the #pragma type_attribute=__fiq directive. For syntax information, see__fiq, page 153, and #pragma type_attribute, page 166, respectively.
17
Interrupt functions
Note: An interrupt function (irq) and a fast interrupt function (fiq) must have a return type of void and cannot have any parameters. A software interrupt function (swi) may have parameters and return values. By default, only four registers, R0R3, can be used for parameters and only the registers R0R1 can be used for return values.
NESTED INTERRUPTS
Interrupts are automatically disabled by the ARM core prior to entering an interrupt handler. If an interrupt handler re-enables interrupts, calls functions, and another interrupt occurs, then the return address of the interrupted functionstored in LRis overwritten when the second IRQ is taken. In addition, the contents of SPSR will be destroyed when the second interrupt occurs. The __irq keyword itself does not save and restore LR and SPSR. To make an interrupt handler perform the necessary steps needed when handling nested interrupts, the keyword __nested must be used in addition to __irq. The function prologfunction entrance sequencethat the compiler generates for nested interrupt handlers will switch from IRQ mode to system mode. Make sure that both the IRQ stack and system stack is set up. If you use the default cstartup.s79 file, both stacks are correctly set up. Compiler-generated interrupt handlers that allow nested interrupts are supported for IRQ interrupts only. The FIQ interrupts are designed to be serviced quickly, which in most cases mean that the overhead of nested interrupts would be too high. This example shows how to use nested interrupts with the ARM vectored interrupt controller (VIC):
__irq __nested __arm void interrupt_handler(void) { void (*interrupt_task)(); unsigned int vector; vector = VICVectAddr; // Get interrupt vector. interrupt_task = (void(*)())vector; VICVectAddr = 0; __enable_interrupt(); // Acknowledge interrupt in VIC. // Allow other IRQ interrupts to be serviced from this point. // Execute the task associated with this interrupt.
(*interrupt_task)(); }
18
Reference Guide
Functions
SOFTWARE INTERRUPTS
Software interrupt functions are slightly more complex, in the way that they accept arguments and have return values. The __swi keyword also expects a software interrupt number which is specified with the #pragma swi_number=number directive. A __swi function can for example be declared in the following way:
#pragma swi_number=0x23 __swi __arm int swi_function(int a, int b);
The swi_number is used as an argument to the generated assembler SWI instruction, and can be used to select one software interrupt function in a system containing several such functions. For additional information, see __swi, page 155, and #pragma swi_number, page 166, respectively.
19
Interrupt functions
Note that the branch instruction must be sufficient to reach the interrupt function. The chapter Assembler language interface contains more information about the runtime environment used by interrupt routines. See the ARM core documentation for more information about the interrupt vector table.
INTERRUPT OPERATIONS
An interrupt function is called when an external event occurs. Normally it is called immediately while another function is executing. When the interrupt function has finished executing, it returns to the original function. It is imperative that the environment of the interrupted function is restored; this includes the value of processor registers and the processor status register. When an interrupt occurs, the following actions are performed:
The operating mode is changed corresponding to the particular exception The address of the instruction following the exception entry instruction is saved in R14 of the new mode The old value of the CPSR is saved in the SPSR of the new mode Interrupt requests are disabled by setting bit 7 of the CPSR and, if the exception is a fast interrupt, further fast interrupts are disabled by setting bit 6 of the CPSR The PC is forced to begin executing at the relevant vector address.
20
Reference Guide
Functions
For example, if an interrupt for vector 0x18 occurs, the processor will start to execute code at address 0x18. The memory area that is used as start location for interrupts is called the interrupt vector table. The content of the interrupt vector is normally a branch instruction jumping to the interrupt routine. Note: If the interrupt function enables interrupts, the special processor registers needed to return from the interrupt routine must be assumed to be destroyed. For this reason they must be stored by the interrupt routine to be restored before it returns. This is handled automatically if the __nested keyword is used.
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 existing before the function call is also restored. Note: If a monitor function is called while the processor is executing in user mode, the function will not be able to change the interrupt settings. To define a monitor function, the __monitor keyword can be used. Example In the following example, a semaphore is implemented using one static variable and two monitor functions. A semaphore can be locked by one process, and is used for preventing processes from simultaneously using resources that can only be used by one process at a time, for example a printer.
/* When the_lock is non-zero, someone owns the lock. */ static unsigned int the_lock = 0; /* get_lock -- Try to lock the lock. * Return 1 on success and 0 on failure. */ __monitor int get_lock(void) { if (the_lock == 0) { /* Success, we managed to lock the lock. */ the_lock = 1; return 1; } else { /* Failure, someone else has locked the lock. */ return 0; }
21
Function directives
Function directives
The function directives FUNCTION, ARGFRAME, LOCFRAME, and FUNCALL are generated by the ARM IAR C/C++ Compiler to pass information about functions and function calls to the IAR XLINK Linker. These directives can be seen if you create an assembler list file with the compiler option Assembler file (-lA).
22
Reference Guide
Functions
Note: These directives are primarily intended to support static overlay, a feature which is useful in smaller microcontrollers. The ARM IAR C/C++ Compiler does not use static overlay, as it has no use for it. For reference information about the function directives, see the ARM IAR Assembler Reference Guide.
23
Function directives
24
Reference Guide
WHAT IS A SEGMENT?
A segment is a logical entity containing a piece of data or code that should be mapped to a physical location in memory. Each segment consists of many segment parts. Normally, each function or variable with static storage duration is placed in a segment part. A segment part is the smallest linkable unit, which allows the linker to include only those units that are referred to. The segment could be placed either in RAM or in ROM. Segments that are placed in RAM do not have any content, they only occupy space. The ARM IAR C/C++ Compiler has a number of predefined segments for different purposes. Each segment has a name that describes the contents of the segment, and a segment memory type that denotes the type of content. In addition to the predefined segments, you can define your own segments. At compile time, the compiler assigns each segment its contents. The IAR XLINK Linker is responsible for placing the segments in the physical memory range, in accordance with the rules specified in the linker command file. There are supplied linker command files, but, if necessary, they can be easily 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.
25
For detailed information about individual segments, see the Segment reference chapter in Part 2. Compiler reference.
For executable code For data placed in ROM For data placed in RAM
For more details about segments, see the chapter Segment reference.
The placement of segments in memory The maximum stack size The maximum heap size.
The runtime environment of the compiler uses placeholder segments, empty segments that are used for marking a location in memory. Any type of segment can be used for placeholder segments. This section describes the methods for placing the segments in memory, which means that you have to customize the linker command file to suit the memory layout of your target system. For showing the methods, fictitious examples are used.
26
Reference Guide
ROM or RAM ROM or other non-volatile memory RAM or other read/write memory
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 command file is to verify that your application code and data do not cross the memory range boundaries, which would lead to application failure. Note: In the default linker command file lnkarm.xcl, the start and end addresses for ROM and RAM segments are defined using the -D directive:
-DROMSTART=08000 -DROMEND=FFFFF -DRAMSTART=100000 -DRAMEND=7FFFFF
27
Definitions of constants used later in the file. These are defined using the XLINK option -D. The placement directives (the largest part of the linker command file). Segments can be placed using the -Z and -P options. The former will place the segment parts in the order they are found, while the latter will try to rearrange them to make better use of the memory. The -P option is useful when the memory where the segment should be placed is not continuous.
See the IAR Linker and Library Tools Reference Guide for more details.
Two segments of different types can be placed in the same memory area by not specifying 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=008000-0FFFFF -Z(CODE)MYCODE
Two memory ranges may overlap. This allows segments with different placement requirements to share parts of the memory space; for example:
-Z(CONST)MYSMALLSEGMENT=008000-000FFF -Z(CONST)MYLARGESEGMENT=008000-0FFFFF
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.
28
Reference Guide
The following example illustrates how the XLINK -P option can be used for making efficient use of the memory area. The command will place the data segment MYDATA in DATA memory (that is, in RAM) in a fictitious memory range:
-P(DATA)MYDATA=100000-101FFF,110000-111FFF
If your application has an additional RAM area in the memory range 0x10F000-0x10F7FF, you just add that to the original definition:
-P(DATA)MYDATA=100000-101FFF,10F00010F7FF,110000-111FFF
Data segments
This section contains descriptions of the segments used for storing the different types of data: static, stack, heap, and located.
Variables that are initialized to a non-zero value Variables that are initialized to zero 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.
The segment naming Restrictions for segments holding initialized data The placement and size limitation of the static memory segments.
Segment naming
The actual segment names consist of two partsa segment base name and a suffix that specifies what the segment is used for. In the ARM IAR C/C++ Compiler, the segment base name is HUGE.
Some of the declared data is placed in non-volatile memory, for example ROM, and some of the data is placed in RAM. For this reason, it is also important to know the XLINK segment memory type of each segment. For more details about segment memory types, see Segment memory type, page 26.
29
Data segments
The following table summarizes the different suffixes, which XLINK segment memory type they are, and which category of declared data they denote:
Categories of declared data Segment memory type Suffix
CONST
AC AN C I ID N Z
Absolute addressed located data declared __no_init DATA Constants Non-zero initialized data Initializers for the above Non-initialized data Zero-initialized data
Table 5: Segment name suffixes
For a summary of all supported segments, see Summary of segments, page 117. Examples
The variables that are to be initialized to zero when the system starts will be placed in the segment DATA_Z. The non-initialized variables will be placed in the segment DATA_N. The non-zero initialized variables will be placed in the segment DATA_I.
int j = 4;
Initialized data
When an application is started, the cstartup module initializes static and global variables in two steps: 1 It clears the memory of the variables that should be initialized to zero. 2 It initializes the non-zero variables by copying a block of ROM to the location of the variables in RAM. This means that the data in the ROM segment with the suffix ID is copied to the corresponding I segment. This works when both segments are placed in continuous memory. However, if one of the segments is divided into smaller pieces, it is important that:
The other segment is divided in exactly the same way It is legal to read and write the memory that represents the gaps in the sequence.
30
Reference Guide
For example, if the segments are assigned the following ranges, the copy will fail:
DATA_I DATA_ID 0x100000-0x1000FF and 0x100200-0x1002FF 0x020000-0x0201FF
However, in the following example, the linker will place the content of the segments in identical order, which means that the copy will work appropriately:
DATA_I DATA_ID 0x100000-0x1000FF and 0x100200-0x1002FF 0x020000-0x0200FF and 0x020200-0x0202FF
Note that the gap between the ranges will also be copied.
Data segments for static memory in the default linker command file
The default linker command file contains the following directives to place the static data segments:
//Various constants and initializers -Z(CONST)INITTAB,DATA_ID,DATA_C=ROMSTART-ROMEND
//Data segments
-Z(DATA)DATA_I,DATA_Z,DATA_N=RAMSTART-RAMEND
THE STACK
The stack is used by functions to store variables and other information that is used locally by functions, as described in the chapter Data storage. It is a continuous block of memory pointed to by the processor stack pointer register SP. The data segment used for holding the stack is called CSTACK. The cstartup module initializes the stack pointer to the end of the stack segment. The default linker file sets up a constant representing the size of the stack, at the beginning of the linker file:
-D_CSTACK_SIZE=2000
Note that the size is written hexadecimally without the 0x notation. Further down in the linker file, the actual segment is defined in the memory area available for the stack:
-Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND
31
Data segments
Stack size
The compiler uses the internal data stack, CSTACK, for a variety of user program operations, and the required stack size depends heavily on the details of these operations. If the given stack size is too small, the stack will normally overwrite the variable storage, which is likely to result in program failure. If the given stack size is too large, RAM will be wasted.
Exception stacks
The ARM architecture supports five exception modes which are entered when different exceptions occur. Each exception mode has its own stack to avoid corrupting the System/User mode stack. The table shows proposed stack names for the various exception stacks, but any name can be used.
Proposed stack segment name
Processor mode
Description
Operating system stack. Stack for general-purpose (IRQ) interrupt handlers . Stack for high-speed (FIQ) interrupt handlers . Stack for undefined instruction interrupts. Supports software emulation of hardware coprocessors and instruction set extensions. Stack for instruction fetch and data access memory abort interrupt handlers.
Abort
Table 6: Exception stacks
ABT_STACK
For each processor mode where a stack is needed, a separate stack pointer must be initialized in your startup code, and segment placement should be done in the linker command file. The IRQ stack is the only exception stack which is preconfigured in the supplied cstartup.s79 and lnkarm.xcl files, but other exception stacks can easily be added.
THE HEAP
The heap contains data allocated dynamically by use of the C function malloc (or one of its relatives) or the C++ operator new. The memory allocated to the heap is placed in the segment HEAP. This segment is only included in the application if dynamic memory allocation is actually used.
32
Reference Guide
The size and placement of this segment is defined in the linker command file, much in the same way as the size and placement of the stack. This example is taken from the default linker command file:
-D_HEAP_SIZE=8000
and
-Z(DATA)HEAP+_HEAP_SIZE=RAMSTART-RAMEND
LOCATED DATA
A variable that has been explicitly placed at an address, for example by using the compiler @ syntax, will be placed in either the DATA_AC or the DATA_AN segment. The former is used for constant-initialized data, and the latter for items declared as __no_init. The individual segment part of the segment knows its location in the memory space, and it does not have to be specified in the linker command file.
Code segments
This section contains descriptions of the segments used for storing code, and the runtime environment support of the special function types interrupt, software interrupt, and fast interrupt. For a complete list of all segments, see Summary of segments, page 117.
STARTUP CODE
The segment ICODE contains code used during system setup (cstartup), runtime initialization (cmain), and system termination (cexit). The system setup code is called from the exception vector 0 (the reset vector). In addition, the segments must be placed into one continuous memory space, which means the -P segment directive cannot be used.
33
Code segments
In the default linker command file, the following line states that this segment can be placed anywhere in the 0x080000xFFFFF memory range:
-Z(CODE)ICODE=08000FFFFF
NORMAL CODE
The name of the actual segments are NAME_SUFFIX. For example, the segment CODE_I holds code which executes in RAM and which was initialized by CODE_ID. Code for normal functions is placed in the CODE segment. For each of the segment groups, the following segments are available:
Contents Type Suffix
No suffix
I ID
To simplify this, the linker command file uses the XLINK option -Q to specify automatic setup for copy initialization of segments, also known as scatter loading. This will cause the linker to generate a new initializer segment into which it will place all data content of the code segment. Everything else, such as symbols and debugging information, will still be associated with the code segment. Code in the application must at runtime copy the contents of the initializer segment in ROM to the code segment in RAM. This is very similar to what compilers do for initialized variables.
// __ramfunc code copied to and executed from RAM -Z(DATA)CODE_I=RAMSTART-RAMEND -QCODE_I=CODE_ID
EXCEPTION VECTORS
The exception vectors are placed in the segment INTVEC which is normally located at address 0. The linker directive would then look like this:
-Z(CODE)INTVEC=00-3F
If the exception vectors contain a branch to the exception handlers, the exception handlers must be located within reach of the branch instruction. If instead a load pc instruction is located at the exception vector, there are no placement restrictions. The above is also valid for the __iar_swi_handler function, a software interrupt handler that is provided with the product. This function is included in the C libraries and is located in the SWITAB segment. Its source code is available in the arm\src\lib directory, in case you need to modify this function.
34
Reference Guide
35
Example
__no_init char alpha @ 0x1000; /* OK */ #pragma location=0x1004 const int beta; const int gamma @ 0x1008 = 3; int delta @ 0x100C;
Note: A variable placed in an absolute location should be defined in an include file, to be included in every module that uses the variable. An unused definition in a module will be ignored. A normal extern declarationone that does not use an absolute placement directivecan refer to a variable at an absolute address; however, optimizations based on the knowledge of the absolute address cannot be performed.
/* OK */
const int gamma @ "MYSEGMENT" = 3; /* OK */ int delta @ "MYSEGMENT"; /* Error, neither */ /* "__no_init" nor "const" */
36
Reference Guide
Example
void f(void) @ "MYSEGMENT"; void g(void) @ "MYSEGMENT" { } #pragma location="MYSEGMENT" void h(void);
In C++, const variables are static (module local), which means that each module with this declaration will contain a separate variable. When you link an application with several such modules, the linker will report that there are more than one variable located at address 0x100. To avoid this problem and have it work the same way in C and C++, you should declare these SFRs extern, for example:
extern volatile const __no_init int x @ 0x100;
37
Some instructions do not work unless a certain condition holds after linking, for example that a branch must be within a certain distance or that an address must be even. XLINK verifies that the conditions hold when the files are linked. If a condition is not satisfied, XLINK generates a range error or warning and prints a description of the error. For further information about these types of errors, see the IAR Linker and Library Tools Reference Guide.
A segment map which lists all segments in dump order A module map which lists all segments, local symbols, and entries (public symbols) for every module in the program. All symbols not included in the output can also be listed Module summary which lists the contribution (in bytes) from each module A symbol list which contains every entry (global symbol) in every module.
Use the option Generate linker listing in the Embedded Workbench, or the option -X on the command line, and one of their suboptions to generate a linker listing. Normally, XLINK will not generate an output file if there are any errors, such as range errors, during the linking process. Use the option Range checks disabled in the Embedded Workbench, or the option -R on the command line, to generate an output file even if a range error was encountered. For further information about the listing options and the linker listing, see the IAR Linker and Library Tools Reference Guide, and the ARM IAR Embedded Workbench IDE User Guide.
38
Reference Guide
39
The runtime environment also consists of a part with specific support for the target system, which includes:
Support for hardware features: Direct access to low-level processor operations by means of intrinsic functions, such as functions for register handling Peripheral unit registers and interrupt definitions in include files The Vector Floating Point (VFP) coprocessor. Runtime environment support, that is, startup and exit code and low-level interface to some library functions. Special compiler support for some functions, for instance functions for floating-point arithmetics
Some parts, like the startup and exit code and the size of the heap must be tailored for the specific hardware and application requirements. If you build your application project with the XLINK options With runtime control modules (-r) or With I/O emulation modules (-rt), certain functions in the library, such as functions for I/O and exit, will be replaced by functions that communicate with the IAR C-SPY Debugger. For further information, see C-SPY Debugger runtime interface, page 62. For further information about the library, see the chapter Library functions.
LIBRARY SELECTION
To configure the most code-efficient runtime environment, you must determine your application and hardware requirements. The more functionality you need, the larger your code will get. The IAR Embedded Workbench comes with a set of prebuilt runtime libraries. To get the required runtime environment, you can customize it by:
Setting library options, for example for choosing scanf input and printf output formatters, and for specifying the size of the stack and the heap Overriding certain library functions, for example cstartup, with your own customized versions Choosing the level of support for certain standard library functionality, for example locale, file descriptors, and multibytes, by choosing a library configuration: normal or full.
In addition, you can also make your own library configuration, but that requires that you rebuild the library. This allows you to get full control of the runtime environment. Note: Your application project must be able to locate the library, include files, and the library configuration file.
40
Reference Guide
There is no prebuilt library for the required combination of compiler options or hardware support You want to define your own library configuration with support for locale, file descriptors, multibytes, et cetera.
For information about how to build a customized library, see Building and using a customized library, page 49.
LIBRARY CONFIGURATIONS
It is possible to configure the level of support for, for example, locale, file descriptors, multibytes. The runtime library configuration is defined in the library configuration file. It contains information about what functionality is part of the runtime environment. The configuration file is used for tailoring a build of a runtime library, as well as tailoring the system header files used when compiling your application. The less functionality you need in the runtime environment, the smaller it is. The following DLIB library configurations are available:
Library configuration Description
No locale interface, C locale, no file descriptor support, no multibytes in printf and scanf, and no hex floats in strtod. Full locale interface, C locale, file descriptor support, multibytes in printf and scanf, and hex floats in strtod.
In addition to these configurations, you can define your own configurations, which means that you must modify the configuration file. Note that the library configuration file describes how a library was built and thus cannot be changed unless you rebuild the library. For further information, see Building and using a customized library, page 49. The prebuilt libraries are based on the default configurations, see Table 9, Prebuilt libraries, page 42. There is also a ready-made library project template that you can use if you want to rebuild the runtime library.
41
Architecture CPU mode Interworking VFP Byte order Stack alignmentall prebuilt libraries are built using stack alignment 8, which is also compatible with stack alignment 4 Library configurationNormal or Full.
For the ARM IAR C/C++ Compiler, this means there is a prebuilt runtime library for each combination of these options. The following table shows the mapping of the library file, architecture, CPU mode, interworking, VFP, byte order, and library configurations:
Library Architecture CPU mode Interworking VFP Byte order Library configuration
dl4tpainb8f.r79 dl4tpainb8n.r79 dl4tpainl8f.r79 dl4tpainl8n.r79 dl4tpannb8f.r79 dl4tpannb8n.r79 dl4tpannl8f.r79 dl4tpannl8n.r79 dl4tptinb8f.r79 dl4tptinb8n.r79 dl4tptinl8f.r79 dl4tptinl8n.r79 dl4tptnnb8f.r79 dl4tptnnb8n.r79 dl4tptnnl8f.r79 dl4tptnnl8n.r79 dl5tpainb8f.r79 dl5tpainb8n.r79
Table 9: Prebuilt libraries
v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v4T v5T v5T
ARM ARM ARM ARM ARM ARM ARM ARM Thumb Thumb Thumb Thumb Thumb Thumb Thumb Thumb ARM ARM
Yes Yes Yes Yes No No No No Yes Yes Yes Yes No No No No Yes Yes
No No No No No No No No No No No No No No No No No No
Big Big Little Little Big Big Little Little Big Big Little Little Big Big Little Little Big Big
Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal
42
Reference Guide
Library
Architecture
CPU mode
Interworking
VFP
Byte order
Library configuration
dl5tpainl8f.r79 dl5tpainl8n.r79 dl5tpaivb8f.r79 dl5tpaivb8n.r79 dl5tpaivl8f.r79 dl5tpaivl8n.r79 dl5tpannb8f.r79 dl5tpannb8n.r79 dl5tpannl8f.r79 dl5tpannl8n.r79 dl5tpanvb8f.r79 dl5tpanvb8n.r79 dl5tpanvl8f.r79 dl5tpanvl8n.r79 dl5tptinb8f.r79 dl5tptinb8n.r79 dl5tptinl8f.r79 dl5tptinl8n.r79 dl5tptnnb8f.r79 dl5tptnnb8n.r79 dl5tptnnl8f.r79 dl5tptnnl8n.r79
v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T v5T
ARM ARM ARM ARM ARM ARM ARM ARM ARM ARM ARM ARM ARM ARM Thumb Thumb Thumb Thumb Thumb Thumb Thumb Thumb
Yes Yes Yes Yes Yes Yes No No No No No No No No Yes Yes Yes Yes No No No No
Little Little Big Big Little Little Big Big Little Little Big Big Little Little Big Big Little Little Big Big Little Little
Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal Full Normal
where
<type> is dl for the IAR DLIB Library <architecture> is the name of the architecture. It can be one of 4t or 5t, for
43
<fpu> is v if the library was compiled with the VFPv1 floating-point support, otherwise it is n for software floating-point support <endian> is one of l, or b, for little-endian and big-endian, respectively <stack_align> reflects the stack alignment used in the library <library_configuraton> is one of n or f for normal and full, respectively.
Note: The library configuration file has the same base name as the library. The IAR Embedded Workbench will include the correct library object file and library configuration file based on the options you select. See the ARM IAR Embedded Workbench IDE User Guide for additional information. On the command line, you must specify the following items:
Specify which library object file to use on the XLINK command line, for instance:
dl4tpainl8n.r79
You can find the library object files and the library configuration files in the subdirectory arm\lib.
Selecting formatters used by printf and scanf by setting the appropriate options Overriding library modules with your own customized versions.
Formatters for printf and scanf Startup and termination code Low-level input and output File input and output Low-level environment functions Low-level signal functions Low-level time functions Size of heaps, stacks, and segments
Table 10: Customizable items
44
Reference Guide
For a description about how to override library modules, see Overriding library modules, page 47.
Overriding default formatters for the printf and scanf functions Setting the sizes of the heap and stack, see page 33.
To override the default formatter for all the printf related functions, except for wprintf variants, and all the scanf-related functions, except for wscanf variants, you simply set the appropriate library options. This section describes the different options available. Note: If you rebuild the library, it is possible to optimize these functions even further, see Configuration symbols for printf and scanf, page 55.
45
* Yes
No No No No No No No No 10%
Conversion specifiers e, E, f, F, g, Yes and G Conversion specifier n Format flag space, +, -, #, and 0 Yes Yes
Length modifiers h, l, L, s, t, and Yes Z Field width and precision, including Yes * long long support Approximate relative size
Table 11: Formatters for printf
Yes 100%
For information about how to fine-tune the formatting capabilities even further, see Configuration symbols for printf and scanf, page 55.
46
Reference Guide
Multibyte support Floating-point support Conversion specifier n Scan set [ and ] Assignment suppressing * long long support Approximate relative size
Table 12: Formatters for scanf
* No No No No No 30%
For information about how to fine-tune the formatting capabilities even further, see Configuration symbols for printf and scanf, page 55.
47
1 Copy the appropriate library_module.c file to your project directory. 2 Make the required additions to the file (or create your own routine, using the default
file as a model), and make sure to save it under the same name.
3 Add the customized file to your project. 4 Rebuild your project. Overriding library modules from the command line
This procedure is applicable to any source file in the library, which means library_module.c in this example can be any module in the library.
1 Copy the appropriate library_module.c to your project directory. 2 Make the required additions to the file (or create your own routine, using the default
file as a model), and make sure to save it under the same name.
3 Compile the modified file using the same options as for the rest of the project:
iccarm library_module
Make sure that library_module is located before the library on the command line. This ensures that your module is used instead of the one in the library. Run XLINK to rebuild your application. This will use your version of library_module.r79, instead of the one in the library. For information about the XLINK options, see the IAR Linker and Library Tools Reference Guide.
48
Reference Guide
Set up a library project Make the required library modifications Build your customized library Finally, make sure your application project will use the customized library.
Information about the build process is described in ARM IAR Embedded Workbench IDE User Guide. Note: It is possible to build IAR Embedded Workbench projects from the command line by using the iarbuild.exe utility. However, no make or batch files for building the library from the command line are provided.
49
1 Choose Project>Options and click the Library Configuration tab in the General
Options category.
2 Choose Custom DLIB from the Library drop-down menu. 3 In the Library file text box, locate your library file. 4 In the Configuration file text box, locate your library configuration file.
50
Reference Guide
cstartup
Program entry label
Hardware setup
cmain
__low_level_init
Static initialization
Application Dynamic C++ initialization Return from main and call exit
main
cexit
_exit exit
abort __exit
System terminated
_Exit
The code for handling startup and termination is located in the source files cstartup.s79, cmain.s79, cexit.s79, and low_level_init.c or low_level_init.s79, located in the arm\src\lib directory.
51
SYSTEM STARTUP
When an application is initialized, a number of steps are performed:
When the cpu is reset it will jump to the program entry label in the cstartup module. Exception stack pointers are initialized to the end of each corresponding segment The stack pointer is initialized to the end of the CSTACK segment The preferred mode is set to ARM or Thumb The function __low_level_init is called, giving the application a chance to perform early initializations Static variables are initialized; this includes clearing zero-initialized memory and copying the ROM image of the RAM memory of the rest of the initialized variables depending on the return value of __low_level_init Static C++ objects are constructed The main function is called, which starts the application.
SYSTEM TERMINATION
An application can terminate normally in two different ways:
Since the ISO/ANSI 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 C. It calls a small function _exit provided by the cstartup file. The _exit function will perform the following operations:
Call functions registered to be executed when the application ends. This includes C++ destructors for static and global variables, and functions registered with the standard C function atexit Close all open files Call __exit When __exit is reached, stop the system.
An application can also exit by calling the abort function. The default abort function just calls __exit in order to halt the system without performing any type of cleanup.
52
Reference Guide
__LOW_LEVEL_INIT
Two skeleton low-level initialization files are supplied with the producta C source file, low_level_init.c and an alternative assembler source file, low_level_init.s79. The latter is part of the prebuilt runtime environment. The only limitation using the C source version is that static initialized variables cannot be used within the file, as variable initialization has not been performed at this point. The value returned by __low_level_init determines whether or not data segments should be initialized by cstartup. If the function returns 0, the data segments will not be initialized.
53
54
Reference Guide
} return nChars; } size_t __read(int Handle, unsigned char *Buf, size_t BufSize) { int nChars = 0; /* Check for stdin (only necessary if FILE descriptors are enabled) */ if (Handle != 0) { return -1; } for (/*Empty*/; BufSize > 0; --BufSize) { int c = LCD_IO; if (c < 0) break; *Buf ++= c; ++nChars; } return nChars; }
For information about the @operator, see Controlling data and function placement, page 35.
_DLIB_PRINTF_MULTIBYTE _DLIB_PRINTF_LONG_LONG
Table 13: Descriptions of printf configuration symbols
55
Floats Hexadecimal floats Output count (%n) Qualifiers h, l, L, v, t, and z Flags -, +, #, and 0 Width and precision Output char by char or buffered
When you build a library, the following configurations determine what capabilities the function scanf should have:
Scanf configuration symbols Includes support for
Multibytes Long long (ll qualifier) Floats Output count (%n) Qualifiers h, j, l, t, z, and L Scanset ([*]) Width
56
Reference Guide
Note that file I/O capability in the library is only supported by libraries with full library configuration, see Library configurations, page 41. In other words, file I/O is supported when the configuration symbol __DLIB_FILE_DESCRIPTOR is enabled. If not enabled, functions taking a FILE * argument cannot be used. Template code for the following I/O files are included in the product:
I/O function File Description
Closes a file. Sets the file position indicator. Opens a file. Reads a character buffer. Writes a character buffer. Removes a file. Renames a file.
The primitive functions identify I/O streams, such as an open file, with a file descriptor that is a unique integer. The I/O streams normally associated with stdin, stdout, and stderr have the file descriptors 0, 1, and 2, respectively. Note: If you link your library with the XLINK option With I/O emulation modules, C-SPY variants of the low-level I/O functions will be linked for interaction with C-SPY. For more information, see C-SPY Debugger runtime interface, page 62.
Locale
Locale is a part of the C language that allows language- and country-specific settings for a number of areas, such as currency symbols, date and time, and multibyte encoding. Depending on what runtime library 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. The DLIB library can be used in two major 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.
57
Locale
All prebuilt libraries supports the C locale only All libraries with full library configuration have support for the locale interface. For prebuilt libraries with locale interface, it is by default only supported to switch multibyte encoding during runtime. Libraries with normal library configuration do not have support for the locale interface.
If your application requires a different locale support, you need to rebuild the library.
The standard C locale The POSIX locale A wide range of international locales.
58
Reference Guide
or
xx_YY.encoding xx specifies the language code, YY specifies a region qualifier, and encoding specifies
the multibyte encoding that should be used. The xx_YY part matches the _LOCALE_USE_XX_YY 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 encoding:
setlocale (LC_ALL, "sv_FI.Utf8");
Environment interaction
Your application can interact with the environment using the functions getenv and system. Note: The putenv function is not required by the standard. The getenv function 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.
59
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
The last string must be empty. 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. This does not require that you rebuild the library. You can find source templates in the files getenv.c and environ.c in the arm\src\lib directory. For information about overriding default library modules, see Overriding library modules, page 47. If you need to use the system function, you need to implement it yourself. The system function available in the library simply returns -1. If you decide to rebuild the library, you can find source templates in the library project template. For further information, see Building and using a customized library, page 49. Note: If you link your application with the XLINK option With I/O emulation modules, the functions getenv and system will be replaced by C-SPY variants. For further information, see C-SPY Debugger runtime interface, page 62.
60
Reference Guide
Time
To make the time and date functions work, you must implement the three functions clock, time, and __getzone. This does not require that you rebuild the library. You can find source templates in the files Clock.c and Time.c, and Getzone.c in the arm\src\lib directory. For information about overriding default library modules, see Overriding library modules, page 47. If you decide to rebuild the library, you can find source templates in the library project template. For further information, see Building and using a customized library, page 49. The default implementation of __getzone specifies UTC as the time-zone. Note: If you link your application with the XLINK option With I/O emulation modules, the functions clock and time will be replaced by C-SPY variants that return the host clock and time respectively. For further information, see C-SPY Debugger runtime interface, page 62.
Strtod
The function strtod does not accept hexadecimal floating-point strings in libraries with the normal library configuration. To make a library do so, you need to rebuild the library, see Building and using a customized library, page 49. Enable the configuration symbol _DLIB_STRTOD_HEX_FLOAT in the library configuration file.
Assert
If you have linked your application with the XLINK options With runtime control modules or With I/O emulation modules, C-SPY will be notified about failed asserts. If this is not the behavior you require, you must add the source file xReportAssert.c to your application project. Alternatively, you can rebuild the library. The __ReportAssert function generates the assert notification.You can find template code in the arm\src\lib directory. For further information, see Building and using a customized library, page 49.
61
abort __exit __read __write __open __close __seek remove rename time clock getenv system _ReportAssert
C-SPY notifies that the application has called abort * C-SPY notifies that the end of the application has been reached *
stdin, stdout, and stderr will be directed to the Terminal I/O window; all other files will read the associated host file stdin, stdout, and stderr will be directed to the Terminal I/O window, all other files will write to the associated host file
Opens a file on the host computer Closes the associated host file on the host computer Seeks in the associated host file on the host computer Writes a message to the Debug Log window and returns -1 Writes a message to the Debug Log window and returns -1 Returns the time on the host computer Returns the clock on the host computer Writes a message to the Debug Log window and returns 0 Writes a message to the Debug Log window and returns -1 Handles failed asserts *
Table 16: Functions with special meanings when linked with debug info * The linker option With I/O emulation modules is not required for these functions.
62
Reference Guide
The mechanism used for implementing this feature works as follows. The debugger will detect the presence of the function __DebugBreak, which will be part of the application if you have linked it with the XLINK options for C-SPY runtime interface. In this case, the debugger will automatically set a breakpoint at the __DebugBreak function. When the application calls, for example open, the __DebugBreak function is called, which will cause the application to break and perform the necessary services. The execution will then resume.
63
Example In the following table, the object files could (but do not have to) define the two runtime attributes color and taste. In this case, file1 cannot be linked with any of the other files, since the runtime attribute color does not match. Also, file4 and file5 cannot be linked together, because the taste runtime attribute does not match. On the other hand, file2 and file3 can be linked with each other, and with either file4 or file5, but not with both.
Object file Color Taste
Note: The predefined runtime attributes all start with two underscores. Any attribute names you specify yourself should not contain two initial underscores in the name, to eliminate any risk that they will conflict with future IAR runtime attribute names. At link time, the IAR XLINK Linker checks module consistency by ensuring that modules with conflicting runtime attributes will not be used together. If conflicts are detected, an error is issued.
64
Reference Guide
Description
__cpu_mode
__pcs__arm Specifies the default cpu mode; see __pcs__thumb --cpu_mode, page 130, for details __pcs__interwork little or big n Specifies the byte order Specifies the compiler runtime model version This runtime key is always present in all modules generated by the ARM IAR C/C++ Compiler. If a major change in the runtime characteristics occurs, the value of this key changes Specifies the stack alignment in bytes. Only one of the two attributes is set at a time.
__endian __rt_version
StackAlign4 StackAlign8
USED
The easiest way to find the proper settings of the RTMODEL directive is to compile a C or C++ module to generate an assembler file, and then examine the file. If you are using assembler routines in the C or C++ code, refer to the chapter Assembler directives in the ARM IAR Assembler Reference Guide.
Implementation of cstartup
This section presents some general techniques used in the cstartup.s79 file, including background information that might be useful if you need to modify it. The cstartup.s79 file itself is well commented and is not described in detail in this guide. Note: Do not modify the cstartup.s79 file unless required by your application. Your first option should always be to use a customized version of __low_level_init for initialization code.
65
Implementation of cstartup
For information about assembler source files, see the ARM IAR Assembler Reference Guide.
66
Reference Guide
EXTERN ?end_of_test REQUIRE ?end_of_test ?do_something: ... // // // // This will be included if someone refers to ?do_something. If this is included then the REQUIRE directive above ensures that the MOV instruction below is included.
RSEG PUBLIC
MYSEG:CODE:NOROOT(2) ?do_something_else
?do_something_else: ... // This will only be included in the linked // application if someone outside this function // refers to or requires ?do_something_else
RSEG PUBLIC
MYSEG:CODE:NOROOT(2) ?end_of_test
Added C functionality
The IAR DLIB Library includes some added C functionality, partly taken from the C99 standard. The following include files are available:
stdint.h stdbool.h
Integer characteristics Bool type; the option Allow IAR extensions (-e) must be used
The functions printf, scanf and strtod have added functionality from the C99 standard. For reference information about these functions, see the library reference available from the Help menu. The following include files have added functionality:
math.h stdio.h
67
Added C functionality
stdlib.h
In math.h all functions exist in a float variant and a long double variant, suffixed by f and l respectively. For example, sinf and sinl. In stdio.h, the following functions have been added:
vscanf, vfscanf, vsscanf, vsnprintf snprintf
Exits without closing files, et cetera. A qsort function that uses the bubble sort algorithm. Useful for applications that have limited stack.
68
Reference Guide
INTRINSIC FUNCTIONS
The compiler provides a small number of 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 in-line code, either as a single instruction, or as a short sequence of instructions.
69
The advantage of an intrinsic function compared with using inline assembler is that the compiler has complete information, and can 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 result. For detailed information about the available intrinsic functions, see the chapter Intrinsic functions.
How should the assembler code be written so that it can be called from C? Where does the assembler code find its parameters, and how is the return value passed back to the caller? How should assembler code call functions written in C? How are global C variables accessed from code written in assembler language? Why does not the debugger display the call stack when assembler code is being debugged?
The first issue is discussed in the section Calling assembler routines from C, page 72. The following three are covered in the section Calling convention, page 75. The answer to the final question is that the call stack can be displayed when you run assembler code in the debugger. However, the debugger requires information about the call frame, which must be supplied as annotations in the assembler source file. For more information, see Call frame information, page 83. It is possible to write parts of your application in assembler and mix them with your C or C++ modules. There are several benefits from this:
The function call mechanism is well-defined The code will be easy to read The optimizer can work with the C or C++ functions.
There will be some overhead in the form of a function call and return instruction sequence, and the compiler will regard some registers as scratch registers. In many cases, the overhead of the function call and return instruction sequence is compensated by the work of the optimizer. The recommended method for mixing C or C++ and assembler modules is described in Calling assembler routines from C, page 72, and Calling assembler routines from C++, page 74, respectively.
70
Reference Guide
INLINE ASSEMBLER
It is possible to insert assembler code directly into a C or C++ function. The asm keyword assembles and inserts the supplied assembler statement in-line. The following example shows how to use inline assembler to insert assembler instructions directly in the C source code. This example also shows the risks of using inline assembler.
bool flag; void foo() { while (!flag) { asm("MOV flag,PIND"); } }
In this example, the assignment of flag is not noticed by the compiler, which means it is not recommended that the surrounding code relies 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 may have on the surrounding code have not been taken into consideration. If, for example, registers or memory locations are altered, they may 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 will possibly also become a maintenance problem if you upgrade the compiler in the future. In addition, there are several limitations to using inline assembler:
The compilers various optimizations will disregard any effects of the inline sequences, which will not be optimized at all The directives CODE16 and CODE32 will cause errors; several other directives cannot be used at all Alignment cannot be controlled; this means, for example, that DC32 directives may be misaligned Auto variables cannot be accessed Labels cannot be declared.
Inline assembler is therefore often best avoided. If there is no suitable intrinsic function available, we recommend the use of modules written in assembler language instead of inline assembler, because the function call to an assembler routine normally causes less performance reduction.
71
Conform to the calling convention Have a PUBLIC entry-point label Be declared as external before any call, to allow type checking and optional promotion of parameters, as in the following examples:
extern int foo(void);
or
extern int foo(int i, int j);
One way of fulfilling these requirements is to create skeleton code in C, compile it, and study the assembler list file.
72
Reference Guide
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 named in the same way as the C or C++ module (skeleton), but with the filename extension s79. Also remember to specify the code model, and optimization level you are using. The result is the assembler source output file skeleton.s79. 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 by using the option -lB instead. Note that CFI information must be included in the source code to make the C-SPY Call Stack window work.
The calling convention The return values The global variables The function parameters How to create space on the stack (auto variables) Call frame information (CFI).
The CFI directives describe the call frame information needed by the Call Stack window in the IAR C-SPY Debugger.
73
Memory access layout of non-PODs ("plain old data structures") is not defined, and may change between compiler versions. Therefore, we do not recommend that you access non-PODs from assembler routines. To achieve the equivalent to a non-static member function, the implicit this pointer has to be made explicit:
class X; extern "C" { void doit(X *ptr, int arg); }
It is possible to wrap the call to the assembler routine in a member function. Using an inline member function removes the overhead of the extra callprovided that function inlining is enabled:
class X { 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.
74
Reference Guide
Calling convention
A calling convention is the way a function in a program calls another function. The compiler handles this automatically, but, if a function is written in assembler language, you must know where and how its parameters can be found, how to return to the program location from where it was called, and how to return the resulting value. It is also important to know which registers an assembler-level routine must preserve. If the program preserves too many registers, the program might be ineffective. If it preserves too few registers, the result would be an incorrect program. This section describes the calling convention used by the ARM IAR C/C++ Compiler. The following issues are described:
Function declarations C and C++ linkage Preserved versus scratch registers Function entrance Function exit Return address handling.
Unless otherwise noted, the calling convention used by the ARM IAR C/C++ Compiler adheres to the Advanced RISC Machines Ltd ARM/Thumb Procedure Call Standard (ATPCS); see the ARM web site.
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 a_function(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.
75
Calling convention
It is often practical to share header files between C and Embedded C++. The following is an example of a declaration that declares a function with C linkage in both C and Embedded C++:
#ifdef __cplusplus extern "C" { #endif int f(int); #ifdef __cplusplus } #endif
Scratch registers
Any function may 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. Any of the registers R0 to R3, and R12, can be used as a scratch register by the function.
Preserved registers
Permanent registers, on the other hand, are preserved across function calls. Any function may use the register for other purposes, but must save the value prior to use and restore it at the exit of the function. The registers R4 through to R11 are preserved registers. They are preserved by the called function.
Special registers
Some registers have special handling that you must consider:
The stack pointer register, R13/SP, must at all times point to or below the last element on the stack. In the eventuality of an interrupt, everything below the point the stack pointer points to, will be destroyed. The register R15/PC is dedicated for the Program Counter. The link register, R14/LR, holds the return address at the entrance of the function.
76
Reference Guide
FUNCTION ENTRANCE
Parameters can be passed to a function using two basic methods: in registers or on the stack. Clearly, it is much more efficient to use registers than to take a detour via memory, so the calling convention is designed to utilize registers as much as possible. There is only a limited number of registers that can be used for passing parameters; when no more registers are available, the remaining parameters are passed on the stack.
Hidden parameters
In addition to the parameters visible in a function declaration and definition, there can be hidden parameters:
If the function returns a structure larger than 32 bits, the memory location where the structure is to be stored is passed as an extra parameter. Notice that it is always treated as the first parameter. If the function is a non-static C++ member function, then the this pointer is passed as the first parameter (but placed after the return structure pointer, if there is one).
Register parameters
The registers available for passing parameters are R0R3:
Parameters Passed in registers
Scalar and floating-point values no larger than 32 bits, and Passed using the first free register: single-precision (32-bits) floating-point values R0R3 Structure values larger than 32 bits Passed using the first free register: R0R3. Any remaining parameters of this type are passed on the stack. Passed in first available register pair: R0:R1, R1:R2, or R2:R3, or divided between the last parameter register and the stack.
The assignment of registers to parameters is a straightforward process. Traversing the parameters from left to right, the first parameter is assigned to the available register or registers. Should there be no more available registers, the parameter is passed on the stack in reverse order. When functions that have parameters smaller than 32 bits are called, the values are sign or zero extended to ensure that the unused bits have consistent values. Whether the values will be sign or zero extended depends on their typesigned or unsigned.
77
Calling convention
If floating-point operations are performed by a Vector Floating Point (VFP) coprocessor, and the compiler is used in non-interworking mode, the following changes are made to the parameter passing convention.
Parameters Passed in registers
Passed using the first free register: S0S15 Passed using the first free register: D0D7
Table 20: VFP registers used for passing parameters in non-interworking mode
For information about how to enable support in the compiler for the VFP coprocessor, see VFP and floating-point arithmetic, page 7.
Stack layout
Stack parameters are stored in memory, starting at the location pointed to by the stack pointer. Below the stack pointer (towards low memory) there is free space that the called function can use. The first stack parameter is stored at the location pointed to by the stack pointer. The next one is stored at the next location on the stack that is divisible by four, etc. It is the responsibility of the caller to clean the stack after the called function has returned.
High address
The callers stack frame Stack parameter n ... Stack parameter 2 Stack parameter 1 Stack pointer
Low address
According to the Advanced RISC Machines Ltd Arm/Thumb Procedure Call Standard (ATPCS; see the ARM web site), the stack should be aligned to 8 at function entry. With the ARM IAR C/C++ Compiler, the stack is by default aligned to 4, but it is possible to align the stack to 8. For information about how to change the stack alignment, see --stack_align, page 148.
78
Reference Guide
FUNCTION EXIT
A function can return a value to the function or program that called it, or it can be of the type void. The return value of a function, if any, can be scalar (such as integers and pointers), floating-point, or a structure.
Scalar and structure return values no larger than 32 bits, and single-precision (32-bit) floating-point return values The memory address of a structure return value larger than 32 bits long long and double-precision (64-bit) return values
Table 21: Registers used for returning values
R0 R0 R0:R1
If the returned value is smaller than 32 bits, the value is sign or zero extended to 32 bits. If floating-point operations are performed by a Vector Floating Point (VFP) coprocessor, and the compiler is used in non-interworking mode, the following changes are made to the parameter passing convention.
Parameters Passed in register/register pair
S0 D0
Table 22: VFP registers used for returning values in non-interworking mode
For information about how to enable support in the compiler for the VFP coprocessor, see VFP and floating-point arithmetic, page 7.
Stack layout
It is the responsibility of the caller to clean the stack after the called function has returned.
79
Calling convention
At function entry, non-scratch registers and the LR register can be pushed with one instruction. At function exit, all these registers can be popped with one instruction. The return address can be popped directly to PC. The following example shows what this can look like in ARM mode:
STMDB . . . LDMIA SP!,{R4-R9,LR} // function entry
SP!,{R4-R9,PC}
// function exit
In Thumb mode, the PUSH and POP instructions will be used instead of STMDB and LDMIA.
EXAMPLES
The following section shows a series of declaration examples and the corresponding calling conventions. The complexity of the examples increases towards the end. Example 1 Assume that we have the following function declaration:
int add1(int);
This function takes one parameter in the register R0, and the return value is passed back to its caller in the register R0. The following assembler routine is compatible with the declaration; it will return a value that is one number higher than the value of its parameter:
add1: ADD MOV R0,R0,#+0x1 PC,LR
Example 2 This example shows how structures are passed on the stack. Assume that we have the following declarations:
struct a_struct { int a,b,c,d,e; }; int a_function(struct a_struct x, int y);
The values of the structure members a, b, c, and d are passed in registers R0-R3. The last structure member e and the integer parameter y are passed on the stack. The calling function must reserve eight bytes on the top of the stack and copy the contents of the two stack parameters to that location. The return value is passed back to its caller in the register R0.
80
Reference Guide
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 R0. The caller assumes that R0 remains untouched. The parameter x is passed in R1. Assume that the function instead would have been declared to return a pointer to the structure:
struct a_struct * a_function(int x);
In this case, the return value is a scalar, so there is no hidden parameter. The parameter x is passed in R0, and the return value is returned in R0.
Calling functions
There are two fundamentally different ways to call functionsdirectly or via a function pointer.This section presents the assembler instructions that can be used for calling and returning from functions. The compiler automatically generates the most efficient assembler instructions to call functions. The normal function calling instruction is the branch-and-link instruction:
BL label
The location that the called function should return to (that is, the location immediately after this instruction) is stored in the link register, LR. With the BL instruction, the destination label may not be further away than 32 Mbytes in ARM mode and 4 Mbytes in Thumb mode. Longer jumps can be made with the BX instruction. This instruction also changes the CPU mode between Thumb and ARM states, if this is required by the called function.
BX reg
For some function calls, it is uncertain whether the branch-and-link instruction can reach the destination address, for example if the calling and called functions are declared in different modules. In such situations, or if the CPU mode changes between Thumb and ARM, the compiler generates a _BLF assembler pseudo instruction. This instruction has two arguments, where the first is a label to the called function, and the second is a label to a module local relay function. This relay function will be used when the called function cannot be reached directly by a simple branch-and-link instruction.
81
Calling functions
The _BLF pseudo instruction will expand to an ordinary BL function instruction if this is sufficientotherwise a BL function_relay will be generated. During segment placement, XLINK will minimize the number of relay functions by letting references in a module use relay functions in adjacent modules whenever possible. Any unused relay functions are simply discarded. The following example shows a simple call to the function func in ARM mode:
_BLF func,func??rA
The call will also generate a relay function func??rA that may be used for calling the function func.
CODE32 func??rA LDR MOV
R12,??RelayData_0 PC,R12
Here the address to the function func is loaded into the register R12 which is then used for calling the function func. The relay function loads somewhat differently in Thumb mode but the functionality is the same. When a function should return control to the caller, the MOV PC,LR instruction will be used if no registers have been pushed at function entry and the STMDB SP!,{RegReg,LR} instruction (in ARM mode) if registers have been saved at function entry. When a function call is made via a function pointer in non-interworking ARM mode, the following code will be generated:
LDR LDR MOV MOV Reg1,function_pointer Reg2,[Reg1,#0] LR,PC PC,Reg2 ; ; ; ; Location of function pointer Load function address Save return address Make function call
The address is stored in a register and is then used for calling the function. Calls via a function pointer reach the whole 32-bit address space.
82
Reference Guide
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.
The following table lists all the resources defined in the names block used by the compiler:
Resource Description
The call frames of the stack Processor general-purpose 32-bit registers Stack pointer, SP Link register, LR Vector Floating Point (VFP) 32-bit coprocessor registers Current program status register Saved program status register The return address
See the ARM IAR Assembler Reference Guide for more information.
83
84
Reference Guide
Using C++
IAR Systems supports two levels of the C++ language: The industry-standard Embedded C++ and IAR Extended Embedded C++. They are described in this chapter.
Overview
Embedded C++ is a subset of the C++ programming language which is intended for embedded systems programming. It was defined by an industry consortium, the Embedded C++ Technical Committee. Performance and portability are particularly important in embedded systems development, which was considered when defining the language.
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 there is a sufficient difference in their argument lists Type-safe memory management using operators new and delete Inline functions, which are indicated as particularly suitable for inline expansion.
C++ features which have been excluded are those that introduce overhead in execution time or code size that are beyond the control of the programmer. Also excluded are recent additions to the ISO/ANSI C++ standard. This is because they represent potential portability problems, due to the fact that few development tools support the standard. Embedded C++ thus offers a subset of C++ which is efficient and fully supported by existing development tools. Standard Embedded C++ lacks the following features of C++:
Templates Multiple and virtual inheritance Exception handling Runtime type information
85
Overview
New cast syntax (the operators dynamic_cast, static_cast, reinterpret_cast, and const_cast) Namespaces 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.
Full template support Multiple and virtual inheritance Namespace support Mutable attribute The cast operators static_cast, const_cast, and reinterpret_cast.
All these added features conform to the C++ standard. To support Extended EC++, this product includes a version of the standard template library (STL), in other words, the C++ standard chapters utilities, containers, iterators, algorithms, and some numerics. This STL has been tailored for use with the Extended EC++ language, which means that there are no exceptions, no multiple inheritance, 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.
86
Reference Guide
Using C++
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
Feature descriptions
When writing C++ source code for the IAR C/C++ Compiler, there are some benefits and some possible quirks that you need to be aware of when mixing C++ featuressuch as classes, and class memberswith IAR language extensions, such as IAR-specific attributes.
CLASSES
A class type class and struct in C++ can have static and non-static data members, and static and non-static function members. The non-static function members can be further divided into virtual function members, non-virtual function members, constructors, and destructors. For the static data members, static function members, and non-static non-virtual function members the same rules apply as for statically linked symbols outside of a class. In other words, they can have any applicable IAR-specific type, memory, and object attribute. The non-static virtual function members can have any applicable IAR-specific type, memory, and object attribute as long as a pointer to the member function is implicitly castable to the default function pointer type. The constructors, destructors, and non-static data members cannot have any IAR attributes. For further information about attributes, see Type and object attributes, page 114. Example
class A { public: static __no_init int i @ 0x60;// Uninitialized variable located at address 0x60 static __thumb void f(); // Static Thumb function __thumb void g(); // Thumb function virtual __thumb void th(); // Not allowed in non-interworking ARM mode virtual __arm void ah(); // Not allowed in non-interworking Thumb mode };
87
Feature descriptions
FUNCTIONS
A function with extern "C" linkage is compatible with a function that has C++ linkage. Example
extern "C" { typedef void (*fpC)(void); // A C function typedef }; void (*fpCpp)(void); // A C++ function typedef fpC f1; fpCpp f2; void f(fpC); f(f1); f(f2); // Always works // fpCpp is compatible with fpC
TEMPLATES
Extended EC++ supports templates according to the C++ standard, except for the support of the export keyword. The implementation uses a two-phase lookup which means that the keyword typename has to 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 have to be in include files or in the actual source file.
VARIANTS OF CASTS
In Extended EC++ the following additional C++ cast variants can be used:
const_cast<t2>(t), static_cast<t2>(t), reinterpret_cast<t2>(t).
MUTABLE
The mutable attribute is supported in Extended EC++. A mutable symbol can be changed even though the whole class object is const.
88
Reference Guide
Using C++
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.
89
Feature descriptions
The standard implementation of this function (located in the file exit.c) looks like this:
extern void _exit(int arg); void exit(int arg) { _exit(arg); } _exit(int) is responsible for calling the destructors of global class objects before ending the program.
To avoid interrupts, place a call to the intrinsic function __disable_interrupt before the call to _exit.
90
Reference Guide
Taking advantage of the compilation system Selecting data types and placing data in memory Writing efficient code.
As a part of this, the chapter also demonstrates some of the more common mistakes and how to avoid them, and gives a catalog of good coding techniques.
91
(Best debug support) Variables live through their entire scope Limited live-range for variables Live-dead analysis and optimization Dead code elimination Redundant label elimination Redundant branch elimination Code hoisting Peephole optimization Some register content analysis and optimization Static clustering Common subexpression elimination (Maximum optimization) Instruction scheduling Cross jumping Advanced register content analysis and optimization Loop unrolling Function inlining Code motion Type-based alias analysis
High
Normally, you would use the same optimization level for an entire project or file, but it is often worthwhile to use different optimization settings for different files in a project. For example, put code that must run very quickly into a separate file and compile it for minimal execution time (maximum speed), and the rest of the code for minimal code size. This will give a small program, which is still fast enough where it matters. The #pragma optimize directive allows you to fine-tune the optimization for specific functions, such as time-critical functions.
92
Reference Guide
A high level of optimization will result in increased compile time, and may also make debugging more difficult, since it will be less clear how the generated code relates to the source code. At any time, if you experience difficulties when debugging your code, try lowering the optimization level. Both compiler options and pragma directives are available for specifying the preferred type and level of optimization. The chapter Compiler options contains reference information about the command line options used for specifying optimization type and level. Refer to the ARM IAR Embedded Workbench IDE User Guide for information about the compiler options available in the IAR Embedded Workbench. Refer to #pragma optimize, page 162, for information about the pragma directives that can be used for specifying optimization type and level.
Common sub-expression elimination Loop unrolling Function inlining Code motion Type-based alias analysis Static clustering Instruction scheduling
Common subexpression elimination Redundant re-evaluation of common subexpressions is by default eliminated at optimization levels Medium and High. This optimization normally reduces both code size and execution time. However, the resulting code might be difficult to debug. Note: This option has no effect at optimization level Low and None. Loop unrolling It is possible to duplicate the loop body of a small loop, whose number of iterations can be determined at compile time, to reduce the loop overhead. This optimization, which can be performed at optimization level High, normally reduces execution time, but increases code size. The resulting code might also be difficult to debug. The compiler heuristically decides which loops to unroll. Different heuristics are used when optimizing for speed and size.
93
Note: This option has no effect at optimization levels None, Low and Medium. Function inlining Function inlining means that a simple 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, which is performed at optimization level High, normally reduces execution time, but increases code size. The resulting code might also be difficult to debug. The compiler decides which functions to inline. Different heuristics are used when optimizing for speed and size. Note: This option has no effect at optimization levels None, Low and Medium. Code motion Evaluation of loop-invariant expressions and common sub-expressions are moved to avoid redundant reevaluation. This optimization, which is performed at optimization level High, 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 None, and Low. Type-based alias analysis A C/C++ application that conforms to the ISO/ANSI standard accesses an object only by an lvalue that has one of the following types:
a const or volatile qualified version of the declared type of the object a type that is the signed or unsigned type corresponding to a const or volatile qualified version of the declared type of the object an aggregate or union type that includes one of the aforementioned types among its members a character type.
By default, the compiler is free to assume that objects are only accessed through the declared type or through unsigned char. However, at optimization level High the type-based alias analysis optimization is used, which means that the optimizer will assume that the program is standards compliant and the rules above will be used for determining what objects may be affected when a pointer indirection is used in an assignment. Consider the following example:
short s; unsigned short us; long l;
94
Reference Guide
unsigned long ul; float f; unsigned short *usptr; char *cptr; struct A { short s; float f; } a; void test(float *fptr, long *lptr) { /* May affect: */ *lptr = 0; /* l, ul */ *fptr = 1.0; /* f, a */ *usptr = 4711; /* s, us, a */ *cptr = 17; /* s, us, l, ul, f, usptr, cptr, a */ }
Because an object should only be accessed as its declared type (or a qualified version of its declared type, or a signed/unsigned type corresponding to its declared type) it is also assumed that the object that fptr points to will not be affected by an assignment to the object that lptr points to. This may cause unexpected behavior for some non-conforming programs. The following contrived example illustrates one of the benefits of type-based alias analysis and what can happen when a non-conforming program breaks the rules above.
short f(short *sptr, long *lptr) { short x = *sptr; *lptr = 0; return *sptr + x; }
Because the *lptr = 0 assignment cannot affect the object that sptr points to, the optimizer will assume that *sptr in the return statement has the same value as variable x was assigned at the beginning of the function. Hence, it is possible to eliminate a memory access by returning x << 1 instead of *sptr + x.
short fail() { union { short s[2]; long l; } u;
95
When the function fails to pass the address of the same object as both a pointer to short and as a pointer to long for the function f, the result will most likely not be what was expected. Note: This option has no effect at optimization levels None, Low, and Medium. Static clustering When static clustering is enabled, static and global variables 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. Alignment gaps between variables can also be eliminated. Note: This option has no effect at optimization levels None and Low. Instruction scheduling The ARM IAR C/C++ Compiler features an instruction scheduler to increase the performance of the generated code. To achieve that goal, the scheduler rearranges the instructions to minimize the number of pipeline stalls emanating from resource conflicts within the microprocessor. Note: This option has no effect at optimization levels None, Low and Medium.
Use int or long instead of char or short whenever possible, to avoid sign extension or zero extension. In particular, loop indexes should always be int or long to minimize code generation. Also, in Thumb mode, accesses through the stack pointer (SP) is restricted to 32-bit data types, which further emphasizes the benefits of using one of these data types. Use unsigned data types, unless your application really requires signed values. Try to avoid 64-bit data types, such as double and long long.
96
Reference Guide
Bitfields and packed structures generate large and slow code and should be avoided in time-critical applications. Using floating-point types on a microprocessor without a math coprocessor is very inefficient, both in terms of code size and execution speed. Declaring a pointer to const data tells the calling function that the data pointed to will not change, which opens for better optimizations.
For details 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. The ARM IAR C/C++ Compiler supports two floating-point formats32 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. Unless the application requires the extra precision that 64-bit floating-point numbers give, we recommend using 32-bit floats instead. Also consider replacing code using floating-point operations with code using integers since these are more efficient. Note that 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, 1 is added and the result is converted back to a float: float test(float a) { return a+1.0; }
To treat a floating-point constant as a float rather than as a double, add an f to it, for example:
float test(float a) { return a+1.0f; }
97
Network communication protocols are usually specified in terms of data types with no padding in between There is a need to save data memory.
For information about alignment requirements, see Alignment, page 107. There are two ways to solve the problem:
Use #pragma pack directive. This is an easy way to remove the problem with the drawback that each access to an unaligned element in the structure will use more code. Write your own customized functions for packing and unpacking structures. This is a more portable way and there will not be any more code produced apart for your functions. The drawback is the need for two views on the structure datapacked and unpacked.
For further details about the #pragma pack directive, see #pragma pack, page 163.
98
Reference Guide
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 the following example:
__no_init volatile union { unsigned char IOPORT; struct { unsigned char way: 1; unsigned char out: 1; }; } @ 0x1234;
This declares an I/O register byte IOPORT at the address 0x1234. The I/O register has 2 bits declared, way and out. Note that both the inner structure and the outer union are anonymous. The following example illustrates how variables declared this way can be used:
void test(void) { IOPORT = 0; way = 1; out = 1; }
The use of local variables is preferred over static or global variables. The reason is that the optimizer must assume, for example, that called functions may modify non-local variables.
99
Avoid taking the address of local variables using the & operator. There are two main reasons why this is inefficient. First, the variable must be placed in memory, and thus cannot be placed in a processor register. This results in larger and slower code. Second, the optimizer can no longer assume that the local variable is unaffected over function calls. Module-local variablesvariables that are declared staticare preferred over global variables. Also avoid taking the address of frequently accessed static variables. The compiler is capable of inlining functions. This means that instead of calling a function, the compiler inserts the content of the function at the location where the function was called. The result is a faster, but often larger, application. Also, inlining may enable further optimizations. The compiler often inlines small functions declared static. The use of the #pragma inline directive and the C++ keyword inline gives the application developer fine-grained control, and it is the preferred method compared to the traditional way of using preprocessor macros. Too much inlining can decrease performance due to the limited number of ARM registers. This feature can be disabled using the --no_inline command line option; see --no_inline, page 142. Avoid using inline assembler. Instead, try writing the code in C or C++, use intrinsic functions, or write a separate module in assembler language. For more details, see Mixing C and assembler, page 69.
If stack space is limited, avoid long call chains and recursive functions. Declare variables with a short life span as auto variables. When the life spans for these variables end, the previously occupied memory can then be reused. Globally declared variables will occupy data memory during the whole program execution. Be careful with auto variables, though, as the stack size can exceed its limits. Avoid passing large non-scalar parameters, such as structures, to functions; in order to save stack space, you should instead pass them as pointers or, in EC++, as references.
FUNCTION PROTOTYPES
It is possible to declare and define functions using two different styles:
100
Reference Guide
Both styles are included in the C standard; however, it is recommended to use the prototyped style, since it makes it easier for the compiler to find problems in the code. In addition, using the prototyped style will make it possible to generate more efficient code, since type promotion (implicit casting) is not needed. The K&R style is only supported for compatibility reasons. To make the compiler verify that all functions have proper prototypes, use the compiler option --require_prototypes.
Prototyped style
In prototyped function declarations, the type for each parameter must be specified.
int test(char, int); int test(char a, int b) { ..... } /* declaration */ /* definition */
101
In the following example an 8-bit character, a 32-bit integer, and twos complement is assumed:
void f1(unsigned char c1) { if (c1 == ~0x80) ; }
Here, the test is always false. On the right hand side, 0x80 is 0x00000080, and ~0x00000080 becomes 0xFFFFFF7F. On the left hand side, c1 is an 8-bit unsigned character, and, thus, cannot be larger than 255. It also cannot be negative, thus the integral promoted value can never have the top 24 bits set.
102
Reference Guide
Note: Each header file contains one section used by the compiler, and one section used by the assembler. Example SFRs with bitfields are declared in the header file. The following example is from ioks32c5000a.h:
/* system configuration typedef struct { __REG32 se :1; __REG32 ce :1; __REG32 we :1; __REG32 cm :2; __REG32 isbp :10; __REG32 srbbp :10; __REG32 ce :6; } __syscfg_bits; register */ /* stall enable, must be 0 */ /* cache enable */ /* /* /* /* cache mode */ internal SRAM base pointer */ special register bank base pointer */ cache enable */
__IO_REG32_BIT(__SYSCFG,0x03FF0000,__READ_WRITE,__syscfg_bits);
By including the appropriate include file into the user code it is possible to access either the whole register or any individual bit (or bitfields) from C code as follows:
// whole register access __SYSCFG = 0x12345678; // Bitfield accesses __SYSCFG_bit.we = 1; __SYSCFG_bit.cm = 3;
You can also use the header files as templates when you create new header files for other ARM derivatives.
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 separate segments, according to the specified memory keyword. See the chapter Placing code and data 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.
103
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 information about the __no_init keyword, see page 154. Note that to use this keyword, language extensions must be enabled; see -e, page 135. For information about the #pragma object_attribute, see page 161.
104
Reference Guide
Data representation Segment reference Compiler options Extended keywords Pragma directives The preprocessor Intrinsic functions Library functions Implementation-defined behavior IAR language extensions Diagnostics.
105
106
Data representation
This chapter describes the data types, pointers, and structure types supported by the ARM IAR C/C++ Compiler. See the chapter Efficient coding for embedded applications for information about which data types provide the most efficient code for your application.
Alignment
Every C data object has an alignment that controls how the object can be stored in memory. Should an object have an alignment of, for example, four, it must be stored on an address that is divisible by four. The reason for the concept of alignment is that some processors have hardware limitations for how the memory can be accessed. Assume that a processor can read 4 bytes of memory using one instruction, but only when the memory read is placed on an address divisible by 4. Then, 4-byte objects, such as long integers, will have alignment 4. Another processor might only be able to read 2 bytes at a time; in that environment, the alignment for a 4-byte long integer might be 2. A structure type will inherit the alignment from its components. All objects must have a size that is a multiple of the alignment. Otherwise, only the first element of an array would be placed in accordance with the alignment requirements. In the following example, the alignment of the structure is 4, under the assumption that long has alignment 4. Its size is 8, even though only 5 bytes are effectively used.
struct str { long a; char b; };
In standard C, the size of an object can be accessed using the sizeof operator.
107
Byte order
Objects with alignment 4 must be stored at an address dividable by 4, while objects with alignment 2 must be stored at addresses dividable by 2. The ARM IAR C/C++ Compiler ensures this by assigning an alignment to every data type, ensuring that the ARM core will be able to read the data.
Byte order
The ARM core stores data in either little-endian or big-endian byte order. To specify the byte order, use the --endian option; see --endian, page 136. In the little-endian byte order, which is default, 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 may be necessary to to use the #pragma bitfields=reversed directive to be compatible with code for other compilers and the I/O register definitions of some derivatives; see #pragma bitfields, page 158.
INTEGER TYPES
The following table gives the size and range of each integer data type:
Data type Size Range Alignment
char signed char unsigned char short signed short unsigned short int signed int unsigned int long signed long
Table 25: Integer types
8 bits 8 bits 8 bits 16 bits 16 bits 16 bits 32 bits 32 bits 32 bits 32 bits 32 bits
0 to 255 -128 to 127 0 to 255 -32768 to 32767 -32768 to 32767 0 to 65535 -231 to 231-1 -231 to 231-1 0 to 232-1 -2
31
1 1 1 2 2 2 4 4 4 4 4
to
231-1
-231 to 231-1
108
Reference Guide
Data representation
Data type
Size
Range
Alignment
unsigned long long long signed long long unsigned long long
Table 25: Integer types
0 to 232-1 -2
63
4 4 4 4
to
263-1
-263 to 263-1 0 to 2
64-1
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 stdbool.h file. This will also enable the Boolean values false and true.
Bitfields
In ISO/ANSI C, int and unsigned int can be used as the base type for integer bitfields. In the ARM IAR C/C++ Compiler, any integer type can be used as the base type when language extensions are enabled.
109
Bitfields in expressions will have the same data type as the integer base type. By default, the compiler places bitfield members from the least significant to the most significant bit in the container type. By using the directive #pragma bitfields=reversed, the bitfield members are placed from the most significant to the least significant bit.
FLOATING-POINT TYPES
Floating-point values are represented by 32- and 64-bit numbers in standard IEEE format. The ranges and sizes for the different floating-point types are:
Type Size Range (+/-) Decimals Exponent Mantissa
float double
32 bits 64 bits
7 15
8 bits 11 bits
23 bits 52 bits
The precision of the float operators (+, -, *, and /) is approximately 7 decimal digits.
110
Reference Guide
Data representation
The precision of the float operators (+, -, *, and /) is approximately 15 decimal digits.
Special cases
The following applies to both 32-bit and 64-bit floating-point formats:
Zero is represented by zero mantissa and exponent. The sign bit signifies positive or negative zero. Infinity is represented by setting the exponent to the highest value and the mantissa to zero. The sign bit signifies positive or negative infinity. 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. Denormalized numbers are used to represent 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 denormalized, even though the number is treated as if the exponent would have been 1. Unlike normal numbers, denormalized numbers do not have an implicit 1 as MSB of the mantissa. The value of a denormalized 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.
Pointer types
The ARM IAR C/C++ Compiler has two basic types of pointers: code pointers and data pointers.
CODE POINTERS
The size of all code pointers is 32 bits and the range is 0x00xFFFFFFFF.
When function pointer types are declared, attributes are inserted before the * sign, for example:
typedef void (__thumb __interwork * IntHandler) (void);
DATA POINTERS
There is one data pointer available. Its size is 32 bits and the range is 0x00xFFFFFFFF.
111
Structure types
CASTING
Casts between pointers have the following characteristics:
Casting a value of an integer type to a pointer of a smaller type is performed by truncation Casting a value of an unsigned integer type to a pointer of a larger type is performed by zero extension Casting a value of a signed integer type to a pointer of a larger type is performed by sign extension Casting a pointer type to a smaller integer type is performed by truncation Casting a pointer type to a larger integer type is performed by zero extension Casting a data pointer to a function pointer and vice versa is illegal Casting a function pointer to an integer type gives an undefined result.
size_t
size_t is the unsigned integer type required to hold the maximum size of an object. In the ARM IAR C/C++ Compiler, the size of size_t is 32 bits.
ptrdiff_t
ptrdiff_t is the type of the signed integer required to hold the difference between two
pointers to elements of the same array. In the ARM IAR C/C++ Compiler, the size of
ptrdiff_t is 32 bits.
intptr_t
intptr_t is a signed integer type large enough to contain a void *. In the ARM IAR C/C++ Compiler, the size of intptr_t is 32 bits. intptr_t is defined in the system include file stdint.h.
uintptr_t
uintptr_t is equivalent to intptr_t, with the exception that it is unsigned. uintptr_t is defined in the system include file stdint.h.
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.
112
Reference Guide
Data representation
ALIGNMENT
The struct and union types inherit the alignment requirements of their members. In addition, the size of a struct is adjusted to allow arrays of aligned structure objects.
GENERAL LAYOUT
Members of a struct (fields) are always allocated in the order given in the declaration. The members are placed in memory according to the given alignment (offsets). Example
struct { short s; /* stored char c; /* stored /* pad in long l; /* stored char c2; /* stored /* pad in } s; in byte 0 and 1 */ in byte 2 */ byte 3 */ in byte 4, 5, 6, and 7 */ in byte 8 */ byte 9, 10 and 11 */
where N are pad bytes. The alignment of the struct is 4 bytes and its size is 12 bytes. The structure itself has the same alignment as the field with the highest alignment requirement. For example:
struct { short s; } s2;
113
will be placed:
s.s s.c 4 bytes s.1 4 bytes s.c2
114
Reference Guide
Data representation
TYPE ATTRIBUTES
Type attributes define how a function is called, or how a data object is accessed. This means that type attributes must be specified both when they are defined and in the declaration. You can either place the type attributes directly in your source code, or use the pragma directive #pragma type_attribute. The following general type attributes are available:
Function type attributes change the calling convention of a function: __arm, __fiq, __interwork, __irq, __monitor, __swi, and __thumb Data type attributes: const and volatile
For each level of indirection, you can specify as many type attributes as required.
OBJECT ATTRIBUTES
Object attributes affect function and data objects, but not how the function is called or how the data is accessed. The object attribute does not affect the object interface. This means that an object attribute does not need to be present in the declaration of an object. The following object attributes are available:
Object attributes that can be used for variables: __no_init Object attributes that can be used for functions and variables: location, @, and
__root
Object attributes that can be used for functions: intrinsic, __ramfunc, and
vector
Note: The intrinsic attribute is reserved for compiler internal use only. You can specify as many object attributes as required.
Shared access; the object is shared between several tasks in a multitasking environment Trigger access; as for a memory-mapped SFR where the fact that an access occurs has an effect
115
Modified access; where the contents of the object can change in ways not known to the compiler.
116
Reference Guide
Segment reference
The ARM IAR C/C++ Compiler places code and data into named segments which are referred to by the IAR XLINK Linker. Details about the segments are required for programming assembler language modules, and are also useful when interpreting the assembler language output from the compiler. For information about how to define segments in the linker command file, see Customizing the linker command file, page 27.
Summary of segments
The table below lists the segments that are available in the ARM IAR C/C++ Compiler. Note that located denotes absolute location using the @ operator or the #pragma location directive. The XLINK segment memory type CODE, CONST, or DATA indicates whether the segment should be placed in ROM or RAM memory areas; see Table 3, XLINK segment memory types, page 26.
Segment Description Type
CODE CODE_I CODE_ID CSTACK DATA_AC DATA_AN DATA_C DATA_I DATA_ID DATA_N DATA_Z DIFUNCT HEAP
Holds code Holds code declared __ramfunc Holds code copied to CODE_I at startup (ROM) Holds the stack used by C or C++ programs Located initialized const objects Located objects, declared with the __no_init keyword Constant data, including string literals Static and global variables declared with non-zero initial values Initial values copied to DATA_I at cstartup Static and global variables, declared with the __no_init keyword Static and global variables, declared without an initial value or with zero initial values Holds pointers to code, typically C++ constructors, which should be executed by cstartup before main is called. Heap segment for dynamically allocated data
CODE DATA CONST DATA CONST DATA CONST DATA CONST DATA DATA CODE DATA
117
Descriptions of segments
Segment
Description
Type
Startup code Addresses and sizes of segments to be initialized at startup Reset and exception vectors Stack for interrupt requests, IRQ, exceptions Software interrupt vector table
Descriptions of segments
The following section gives reference information about each segment. Many of the extended keywords supported by the compiler are mentioned here. For detailed information about the keywords, see the chapter Extended keywords.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
CODE_I Holds program code declared __ramfunc; this code will be executed in RAM. The code is copied from CODE_ID during initialization.
Type
Read/(write).
Memory range
This segment can be placed anywhere in memory.
118
Reference Guide
Segment reference
CODE_ID Permanent storage for program code declared __ramfunc that will be executed in RAM. The code is copied to CODE_I during initialization.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
CSTACK Holds the internal data stack. This segment and its length is normally defined in the
where nn is the size of the stack specified as a hexadecimal number and start is the first memory location.
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
Type
Read-only.
119
Descriptions of segments
Memory range
This segment can be placed anywhere in memory.
HEAP Holds dynamically allocated data, in other words data used by malloc and free, and in C++, new and delete.
This segment and its length is normally defined in the linker command file by the command:
-Z(DATA)HEAP+HEAP_SIZE=start-end
where HEAP_SIZE is the size of the heap, start is the lowest possible memory location, and end is the highest possible memory location. Other segments may also be placed in the same range, as long as there is room enough for all of them within that range.
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
DATA_AC Holds const declared objects that have an absolute address and which are either
explicitly initialized to any value, or implicitly initialized to zero by the compiler. These objects are given an absolute location using the @ operator or the #pragma location directive. Because this segment contains objects which already have a fixed address, it should not be defined in the linker command file.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
120
Reference Guide
Segment reference
DATA_AN Holds objects, declared with the __no_init keyword, that have an absolute address.
Because this segment contains objects which already have a fixed address, it should not be defined in the linker command file.
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
DATA_I Holds static and global initialized variables that have been declared with non-zero initial values. The initial values are copied by cstartup from the DATA_ID segment during
initialization.
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
121
Descriptions of segments
DATA_ID Holds initial values for the variables located in the DATA_I segment. These values are copied by cstartup from DATA_ID to DATA_I during system initialization.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
DATA_N Holds variables to be placed in non-volatile memory. These have been allocated by the compiler, declared __no_init or created __no_init by use of the #pragma memory
directive.
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
DATA_Z Holds static and global variables that have been declared without an initial value or with
a zero-initialiezed value. Standard C specifies that such variables be set to zero before they are encountered by the program, so they are set to zero by cstartup during initialization.
Type
Read/write.
122
Reference Guide
Segment reference
Memory range
This segment can be placed anywhere in memory.
ICODE Holds startup code; these functions are reached by a branch instruction from INTVEC.
Type
Read-only.
Memory range
This segment can be placed anywhere within the first 32 Mbytes of memory so that it can be reached from the INTVEC segment.
INITTAB Holds the table containing addresses and sizes of segments that need to be initialized at
startup.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
INTVEC Holds the reset vector and exceptions vectors which contain branch instructions to cstartup, interrupt service routines. etc.
Type
Read-only.
123
Descriptions of segments
Memory range
Must be placed at address range 0x00 to 0x3F.
IRQ_STACK This stack is used when servicing IRQ exceptions. Other stacks may be added as needed for servicing other exception types: FIQ, SVC, ABF, and UND. The cstartup.s79 file
Type
Read/write.
Memory range
This segment can be placed anywhere in memory.
Type
Read-only.
Memory range
This segment can be placed anywhere in memory.
124
Reference Guide
Compiler options
This chapter explains how to set the compiler options from the command line, and gives detailed reference information about each option. Refer to the ARM IAR Embedded Workbench IDE User Guide for information about the compiler options available in the IAR Embedded Workbench and how to set them.
Some options accept a filename, included after the option letter with a separating space. For example, to generate a listing to the file list.lst:
iccarm prog -l list.lst
Some other options accept a string that is not a filename. The string is included after the option letter, but without a space. For example, to define a symbol:
iccarm prog -DDEBUG=1
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. Note that a command line option has a short name and/or a long name:
A short option name consists of one character, with or without parameters. You specify it with a single dash, for example -e A long name consists of one or several words joined by underscores, and it may have parameters. You specify it with double dashes, for example --char_is_signed.
125
SPECIFYING PARAMETERS
When a parameter is needed for an option with a short name, it can be specified either immediately following the option or as the next command line argument. For instance, an include file path of \usr\include can be specified either as:
-I\usr\include
or as:
-I \usr\include
Note: / can be used instead of \ as the directory delimiter. Additionally, output file options can take a parameter that is a directory name. The output file will then receive a default name and extension. When a parameter is needed for an option with a long name, it can be specified either immediately after the equal sign (=) or as the next command line argument, for example:
--diag_suppress=Pe0001
or
--diag_suppress Pe0001
The option --preprocess, however, is an exception, as the filename must be preceded by a space. In the following example, comments are included in the preprocessor output:
--preprocess=c prog
Options that accept multiple values may be repeated, and may also have comma-separated values (without a space), for example:
--diag_warning=Be0001,Be0002
A file specified by '-' is standard input or output, whichever is appropriate. Note: 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; the following example will create a list file called -r:
iccarm prog -l ---r
126
Reference Guide
Compiler options
C_INCLUDE
Specifies directories to search for include files; for example: C_INCLUDE=c:\program files\iar systems\embedded workbench 4.n\arm\inc;c:\headers Specifies command line options; for example: QCCARM=-lA asm.lst -z9
QCCARM
Table 28: Environment variables
0 1 2 3
Compilation successful, but there may have been warnings. There were warnings, provided that the option --warnings_affect_exit_code was used. There were non-fatal errors or fatal compilation errors making the compiler abort. There were fatal errors.
Options summary
The following table summarizes the compiler command line options:
Command line option Description
--char_is_signed --cpu=core
Table 30: Compiler options summary
127
Options summary
Description
Sets the default mode for functions Defines preprocessor symbols Generates debug information
--dependencies[=[i][m]] {filename|directory} Lists file dependencies --diag_error=tag,tag,... --diag_remark=tag,tag,... --diag_suppress=tag,tag,... --diag_warning=tag,tag,... --diagnostics_tables {filename|directory} -dlib_config filename -e --ec++ --eec++ --enable_multibytes --endian={big|b|little|l} -f filename --fpu={VFPv1|VFPv2|VFP9-S|none} --header_context -Ipath --interwork Treats these as errors Treats these as remarks Suppresses these diagnostics Treats these as warnings Lists all diagnostic messages Determines the library configuration file Enables language extensions Enables Standard Embedded C++ syntax Enables Extended Embedded C++ syntax Enables support for multibyte characters Specifies byte order Extends the command line Selects type of floating-point unit Lists all referred source files Specifies include file path Generates interworking code
-l[a|A|b|B|c|C|D][N][H] {filename|directory} Creates list file --library_module --migration_preprocessor_extensions --module_name=name --no_clustering --no_code_motion
Table 30: Compiler options summary (Continued)
Makes library module Extends the preprocessor Sets object module name Disables static clustering Disables code motion optimization
128
Reference Guide
Compiler options
Description
--no_cse --no_inline --no_scheduling --no_tbaa --no_typedefs_in_diagnostics --no_unroll --no_warnings --no_wrap_diagnostics -o {filename|directory} --omit_types --only_stdout --preinclude includefile
Disables common sub-expression elimination Disables function inlining Disables instruction scheduling Disables type-based alias analysis Prevents use of typedef names in diagnostics Disables loop unrolling Disables all warnings Disables wrapping of diagnostic messages Sets object filename Excludes type information Uses standard output only Includes an include file before reading the source file
--preprocess[=[c][n][l]] {filename|directory} Generates preprocessor output --public_equ symbol[=value] -r --remarks --require_prototypes -s[2|3|6|9] --segment tag=segmentname --separate_cluster_for_initilized_variables --silent --stack_align [4|8] --strict_ansi --warnings_affect_exit_code
Table 30: Compiler options summary (Continued)
Defines a global named assembler label Generates debug information Enables remarks Verifies that prototypes are proper Optimizes for speed Assigns name to segment Separates initialized and non-initialized variables Sets silent operation Sets stack alignment Enables strict ISO/ANSI C Warnings affect exit code
129
Descriptions of options
Description
--warnings_are_errors -z[2|3|6|9]
Table 30: Compiler options summary (Continued)
Descriptions of options
The following section gives detailed reference information about each compiler option.
--char_is_signed --char_is_signed
By default, the compiler interprets the char type as unsigned. The --char_is_signed option causes the compiler to interpret the 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. If you use this option, you may get type mismatch warnings from the IAR XLINK Linker, because the library uses unsigned chars. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
--cpu --cpu=core
Use this option to select the processor variant for which the code is to be generated. The default is ARM7TDMI. For additional information, see Processor variant, page 5. This option is related to the Processor configuration option in the General category in the IAR Embedded Workbench.
Use this option to select the default mode for functions. This setting must be the same for all files included in a program, unless they are all compiled with the --interwork option, see page 139, or the __interwork keyword is used, page 153. This option is related to the CPU mode option in the General category in the IAR Embedded Workbench.
130
Reference Guide
Compiler options
-D -Dsymbol[=value] -D symbol[=value]
Use this option to define a preprocessor symbol with the name symbol and the value value. If no value is specified, 1 is used. 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
This option can be used one or more times on the command line. Example You may want to arrange your source to produce either the test or production version of your program, depending on whether the symbol TESTVER was defined. To do this, you would use include sections such as:
#ifdef ... #endif TESTVER additional code lines for test version only
Then, you would select the version required on the command line as follows:
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Preprocessor.
--debug, -r --debug -r
Use the --debug or -r option to make the compiler include information required by the IAR C-SPY Debugger and other symbolic debuggers in the object modules. Note: Including debug information will make the object files larger than otherwise.
131
Descriptions of options
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Output.
Use this option to make the compiler write information to a file about each source code file opened by the compiler. The following modifiers are available:
Option modifier Description
i m
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 extension i. The filename will be the same as the name of the compiled source file, unless a different name has been specified with the option -o, in which case that name will be used. To specify the working directory, replace directory with a period (.). If --dependencies or --dependencies=i is used, the name of each opened source file, including the full path, if available, is output on a separate line. For example:
c:\iar\product\include\stdio.h d:\myproject\include\foo.h
If --dependencies=m is used, the output uses makefile style. For each source 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 a source file. For example:
foo.r79: c:\iar\product\include\stdio.h foo.r79: d:\myproject\include\foo.h
Example 2 To generate a listing of file dependencies to a file called listing.i in the mypath directory, you would use:
iccarm prog --dependencies mypath\listing
132
Reference Guide
Compiler options
Example 3 An example of using --dependencies with a popular make utility, such as gmake (GNU make):
That is, besides 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 -, it works the first time, when the .d files do not yet exist.
--diag_error --diag_error=tag,tag,...
Use this option to classify 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, and the exit code will be non-zero. Example The following example classifies warning Pe117 as an error:
--diag_error=Pe117
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
--diag_remark --diag_remark=tag,tag,...
Use this option to classify diagnostic messages as remarks. A remark is the least severe type of diagnostic message and indicates a source code construct that may cause strange behavior in the generated code. Example The following example classifies the warning Pe177 as a remark:
--diag_remark=Pe177
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
133
Descriptions of options
--diag_suppress --diag_suppress=tag,tag,...
Use this option to suppress diagnostic messages. Example The following example suppresses the warnings Pe117 and Pe177:
--diag_suppress=Pe117,Pe177
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
--diag_warning --diag_warning=tag,tag,...
Use this option to classify 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. Example The following example classifies the remark Pe826 as a warning:
--diag_warning=Pe826
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
Use this option to list all possible diagnostic messages in a named file. This can be very 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. This option cannot be given together with other options. 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 name diagnostics_tables.txt. To specify the working directory, replace directory with a period (.). Example 1 To output a list of all possible diagnostic messages to the file diag.txt, use:
--diagnostics_tables diag
134
Reference Guide
Compiler options
Example 2 If you want to generate a table to a file diagnostics_tables.txt in the working directory, you could use:
--diagnostics_tables .
Each runtime library has a corresponding library configuration file. Use the --dlib_config option to specify the library configuration file for the compiler. Make sure that you specify a configuration file that corresponds to the library you are using. 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 arm\lib. For examples and a list of prebuilt runtime libraries, see Using a prebuilt library, page 42. 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 Building and using a customized library, page 49. To set the related option in the IAR Embedded Workbench, select Project>Options>General Options>Library Configuration.
-e -e
In the command line version of the ARM IAR C/C++ Compiler, language extensions are disabled by default. If you use language extensions such as ARM-specific keywords and anonymous structs and unions in your source code, you must enable them by using this option. Note: The -e option and the --strict_ansi option cannot be used at the same time. For additional information, see Special support for embedded systems, page 9. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
--ec++ --ec++
In the ARM IAR C/C++ 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++.
135
Descriptions of options
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
--eec++ --eec++
In the ARM IAR C/C++ 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++. See Extended Embedded C++, page 46. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
--enable_multibytes --enable_multibytes
By default, multibyte characters cannot be used in C or C++ source code. If you use this option, multibyte characters in the source code are interpreted according to the host computers 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. To set the equivalent option in the IAR Embedded Workbench, choose Project>Options>C/C++ Compiler>Language.
--endian --endian={big|b|little|l}
Specifies the byte order of the generated code and data. By default, the compiler generates code in little-endian byte order. See also Byte order, page 7.
This option is related to the Endian mode option in the General category in the IAR Embedded Workbench.
-f -f filename
Reads command line options from the named file, with the default extension xcl. By default, the compiler accepts command parameters only from the command line itself and the QCCARM environment variable. To make long command lines more manageable, and to avoid any operating system command line length limit, you can use the -f option to specify a command file, from which the compiler reads command line items as if they had been entered at the position of the option.
136
Reference Guide
Compiler options
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 as in the Microsoft Windows command line environment. Example For example, you could replace the command line:
iccarm prog -r "-DUsername=John Smith" -DUserid=463760
with
iccarm prog -r -f userinfo
--fpu --fpu={VFPv1|VFPv2|VFP9-S|none}
Use this option to generate code that carries out floating-point operations using a Vector Floating Point (VFP) coprocessor. By selecting a VFP coprocessor, you will override the use of the software floating-point library for all supported floating-point operations. Select VFPv1 support if you have a vector floating-point unit conforming to architecture VFPv1, such as the VFP10 rev 0. Similarly, select VFPv2 on a system that implements a VFP unit conforming to architecture VFPv2, such as the VFP10 rev 1. VFP9-S is an implementation of the VFPv2 architecture that can be used with the ARM9E family of CPU cores. Selecting the VFP9-S coprocessor is therefore identical to selecting the VFPv2 architecture. By selecting none (default) the software floating-point library is used.
--header_context --header_context
Occasionally, to find the cause of a problem it is necessary to know which header file 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.
137
Descriptions of options
-I -Ipath -I path
Use this option to specify the search path for #include files. This option may be used more than once on a single command line. Following is the full description of the compilers #include file search procedure:
If the name of the #include file is an absolute path, that file is opened. If the compiler encounters the name of an #include file in angle brackets, such as:
#include <stdio.h>
it searches the following directories for the file to include: 1 The directories specified with the -I option, in the order that they were specified. 2 The directories specified using the C_INCLUDE environment variable, if any.
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 the following command for compilation:
iccarm ..\src\src.c -I..\include -I..\debugconfig
Then the following directories are searched in the order listed below for the config.h file, which in this example is located in the dir\debugconfig directory:
dir\include dir\src dir\include dir\debugconfig
Current file. File including current file. As specified with the first -I option. As specified with the second -I option.
138
Reference Guide
Compiler options
Use angle brackets for standard header files, like stdio.h, and double quotes for files that are part of your application. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Preprocessor.
--interwork --interwork
Use this option to generate interworking code. In code compiled with this option, functions will by default be of the type interwork. It is possible to mix files compiled as arm and thumb (using the --cpu_mode option) as long as they are all compiled with --interwork.
-l -l[a|A|b|B|c|C|D][N][H] {filename|directory}
By default, the compiler does not generate a listing. Use this option to generate a listing to a file. The following modifiers are available:
Option modifier Description
a A b
Assembler list file Assembler file with C or C++ source as comments Basic assembler list file. This file has the same contents as a list file produced with -la, except that none of the extra compiler generated information (runtime model attributes, call frame information, frame size information) is included * Basic assembler list file. This file has the same contents as a list file produced with -lA, except that none of the extra compiler generated information (runtime model attributes, call frame information, frame size information) is included * C or C++ list file C or C++ list file with assembler source as comments C or C++ list file with assembler source as comments, but without instruction offsets and hexadecimal byte values No diagnostics in file Include source lines from header files in output. Without this option, only source lines from the primary source file are included
c C (default) D N H
Table 32: Generating a compiler list file (-l) * This makes the list file less useful as input to the assembler, but more useful for reading by a human.
139
Descriptions of options
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 extension lst. The filename will be the same as the name of the compiled source file, unless a different name has been specified with the option -o, in which case that name will be used. To specify the working directory, replace directory with a period (.). Example 1 To generate a listing to the file list.lst, use:
iccarm prog -l list
Example 2 If you compile the file mysource.c and want to generate a listing to a file mysource.lst in the working directory, you could use:
iccarm mysource -l .
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>List.
--library_module --library_module
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. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Output.
If you need to migrate code from an earlier IAR C or C/C++ compiler, you may want to use this option. With this option, the following can be used in preprocessor expressions:
Floating-point expressions Basic type names and sizeof All symbol names (including typedefs and variables).
Note: If you use this option, not only will the compiler accept code that is not standard conformant, but it will also reject some code that does conform to the standard. Important! Do not depend on these extensions in newly written code, as support for them may be removed in future compiler versions.
140
Reference Guide
Compiler options
--module_name --module_name=name
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. To set the object module name explicitly, use the option --module_name=name, for example:
iccarm prog --module_name=main
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. Example The following examplein which %1 is an operating system variable containing the name of the source filewill give duplicate name errors from the linker:
preproc %1.c temp.c iccarm temp.c ; ; ; ; preprocess source, generating temp.c module name is always 'temp'
Note: In this example, preproc is an external utility. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Output.
--no_clustering --no_clustering
When static clustering is enabled, static and global variables 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. Alignment gaps between variables can also be eliminated. Use --no_clustering to disable static clustering. This option is related to the Optimization options in the C/C++ Compiler category in the IAR Embedded Workbench.
141
Descriptions of options
--no_code_motion --no_code_motion
Use this option to disable optimizations that move code. These optimizations, which are performed at optimization levels 6 and 9, normally reduce code size and execution time. However, the resulting code may be difficult to debug. Note: This option has no effect at optimization levels below 6. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
--no_cse --no_cse
Use --no_cse to disable common subexpression elimination. At optimization levels 6 and 9, the compiler avoids calculating the same expression more than once. This optimization normally reduces both code size and execution time. However, the resulting code may be difficult to debug. Note: This option has no effect at optimization levels below 6. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
--no_inline --no_inline
Use --no_inline to disable function inlining. Function inlining means that a simple 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, which is performed at optimization level 9, normally reduces execution time and increases code size. The resulting code may also be difficult to debug. The compiler heuristically decides which functions to inline. Different heuristics are used when optimizing for speed. Note: This option has no effect at optimization levels below 9. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
142
Reference Guide
Compiler options
--no_scheduling --no_scheduling
The ARM IAR C/EC++ Compiler features an instruction scheduler to increase the performance of the generated code. To achieve that goal, the scheduler rearranges the instructions to minimize the number of pipeline stalls emanating from resource conflicts within the microprocessor. Use --no_scheduling to disable the instruction scheduler. This option is related to the Optimization options in the C/C++ Compiler category in the IAR Embedded Workbench.
--no_tbaa --no_tbaa
Use --no_tbaa to disable type-based alias analysis. When this options is not used, the compiler is free to assume that objects are only accessed through the declared type or through unsigned char. See Type-based alias analysis, page 94 for more information. This option is related to the Optimization options in the C/C++ Compiler category in the IAR Embedded Workbench.
--no_typedefs_in_diagnostics --no_typedefs_in_diagnostics
Normally, when a type is printed by the compiler, most commonly in a diagnostic message of some kind, typedef names that were used in the original type are used whenever they make the resulting text shorter. For example,
typedef int (*MyPtr)(char const *); MyPtr p = "foo";
If the --no_typedefs_in_diagnostics option is specified, the error message will be like this:
Error[Pe144]: a value of type "char *" cannot be used to initialize an entity of type "int (*)(char const *)"
--no_unroll --no_unroll
Use this option to disable loop unrolling. The code body of a small loop, whose number of iterations can be determined at compile time, is duplicated to reduce the loop overhead.
143
Descriptions of options
For small loops, the overhead required to perform the looping can be large compared with the work performed in the loop body. The loop unrolling optimization duplicates the body several times, reducing the loop overhead. The unrolled body also opens up for other optimization opportunities, for example the instruction scheduler. This optimization, which is performed at optimization level 9, normally reduces execution time, but increases code size. The resulting code may also be difficult to debug. The compiler heuristically decides which loops to unroll. Different heuristics are used when optimizing for speed and size. Note: This option has no effect at optimization levels below 9. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
--no_warnings --no_warnings
By default, the compiler issues warning messages. Use this option to disable all warning messages. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
--no_wrap_diagnostics --no_wrap_diagnostics
By default, long lines in compiler diagnostic messages are broken into several lines to make the message easier to read. Use this option to disable line wrapping of diagnostic messages.
-o -o {filename|directory}
Use the -o option to specify an output file for object code. If a filename is specified, the compiler stores the object code in that file. If a directory is specified, the compiler stores the object code in that directory, in a file with the same name as the name of the compiled source file, but with the extension r79. To specify the working directory, replace directory with a period (.).
144
Reference Guide
Compiler options
Example 1 To store the compiler output in a file called obj.r79 in the mypath directory, you would use:
iccarm mysource -o mypath\obj
Example 2 If you compile the file mysource.c and want to store the compiler output in a file mysource.r79 in the working directory, you could use:
iccarm mysource -o .
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>General Options>Output Directories.
--omit_types --omit_types
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. The object file will then only contain type information that is a part of a symbols name. This means that the linker cannot check symbol references for type correctness, which is useful when you build a library that should not contain type information.
--only_stdout --only_stdout
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).
Use this option to make the compiler include 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.
145
Descriptions of options
The following table shows the mapping of the available preprocessor modifiers:
Command line option Description
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 extension i. The filename will be the same as the name of the compiled source file, unless a different name has been specified with the option -o, in which case that name will be used. To specify the working directory, replace directory with a period (.). Example 1 To store the compiler output with preserved comments to the file output.i, use:
iccarm prog --preprocess=c output
Example 2 If you compile the file mysource.c and want to store the compiler output with #line directives to a file mysource.i in the working directory, you could use:
iccarm mysource --preprocess=l .
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Preprocessor.
This option is equivalent to defining a label in assembler language by using the EQU directive and exporting it using the PUBLIC directive.
Use the -r or the --debug option to make the compiler include information required by the IAR C-SPY Debugger and other symbolic debuggers in the object modules. Note: Including debug information will make the object files larger than otherwise.
146
Reference Guide
Compiler options
To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Output.
--remarks --remarks
The least severe diagnostic messages are called remarks (see Severity levels, page 211). A remark indicates a source code construct that may cause strange behavior in the generated code. By default, the compiler does not generate remarks. Use this option to make the compiler generate remarks. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
--require_prototypes --require_prototypes
This option forces 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.
-s -s[2|3|6|9]
Use this option to make the compiler optimize the code for maximum execution speed. If no optimization option is specified, the compiler will use the size optimization -z3 by default. If the -s option is used without specifying the optimization level, speed optimization at level 3 is used by default. The following table shows how the optimization levels are mapped:
Option modifier Optimization level
2 3 6 9
Table 34: Specifying speed optimization (-s)
*The most important difference between -s2 and -s3 is that at level 2, all non-static variables will live during their entire scope.
147
Descriptions of options
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. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
Use this option to place any part of your application into separate non-default segments. Any segment name can be used. The valid tags are code and data. By default, data objects are placed into segments named DATA_*, where * is any of AC, AN, C, I, ID, N, or Z. By using the following command line option when compiling all, or part of your application, you can create a number of new segments named SRAM_* for your data objects:
--segment data=SRAM
Similarly, code is normally placed into segments named CODE, CODE_I, and CODE_ID. By using the following command line option, the segments FLASH, FLASH_I, and FLASH_ID are created if needed:
--segment code=FLASH
Separates initialized and non-initialized variables when using variable clustering. Makes the data *_ID segments smaller but can result in larger code.
--silent --silent
By default, the compiler issues introductory messages and a final statistics report. Use --silent 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.
Use this option to increase the stack alignment at function entry from 4 to 8. The default is 4.
148
Reference Guide
Compiler options
--strict_ansi --strict_ansi
By default, the compiler accepts a relaxed superset of ISO/ANSI C (see the chapter IAR language extensions). Use --strict_ansi to ensure that the program conforms to the ISO/ANSI C standard. Note: The -e option and the --strict_ansi option cannot be used at the same time. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Language.
--warnings_affect_exit_code --warnings_affect_exit_code
By default, the exit code is not affected by warnings, as only errors produce a non-zero exit code. With this option, warnings will generate a non-zero exit code. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
--warnings_are_errors --warnings_are_errors
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 compiler option --diag_warning or the #pragma diag_warning directive will also be treated as errors when --warnings_are_errors is used. For additional information, see --diag_warning, page 134 and #pragma diag_warning, page 160. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Diagnostics.
-z -z[2|3|6|9]
Use this option to make the compiler optimize the code for minimum size. If no optimization option is specified, -z3 is used by default. The following table shows how the optimization levels are mapped:
Option modifier Optimization level
2 3
Table 35: Specifying size optimization (-z)
149
Descriptions of options
Option modifier
Optimization level
6 9
Table 35: Specifying size optimization (-z) (Continued)
*The most important difference between -z2 and -z3 is that at level 2, all non-static variables will live during their entire scope.
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. To set the equivalent option in the IAR Embedded Workbench, select Project>Options>C/C++ Compiler>Code.
150
Reference Guide
Extended keywords
This chapter describes the extended keywords that support specific features of the ARM core, the general syntax rules for the keywords, and a detailed description of each keyword. For information about the address ranges of the different memory areas, see the chapter Segment reference.
Makes a function execute in ARM mode Inserts an assembler instruction Declares a fast interrupt function Controls function calling conventions Reserved for compiler internal use only Declares an interrupt function Supports atomic execution of a function
Function execution -Special function type Function execution -Special function type Special function type
151
Extended keyword
Description
Type
__nested
Allows an __irq declared interrupt function to be nested, that is, interruptable by the same type of interrupt Supports non-volatile memory Makes a function execute in RAM
Function execution
Ensures that a function or variable is included Function execution in the object code even if unused Declares a software interrupt function Makes a function execute in Thumb mode Special function type Function execution
functions that also execute in ARM mode. A function declared __arm cannot be declared __thumb. Example
__arm int func1(void);
asm, __asm The asm and __asm extended keywords both insert an assembler instruction. However, when compiling C source code, the asm keyword is not available when the option --strict_ansi is used. The __asm keyword is always available.
Note: Not all assembler directives and operators can be inserted using this keyword.
Syntax
asm ("string");
The string can be a valid assembler instruction or an assembler directive, but not a comment. You can write several consecutive inline assembler instructions, for example:
asm ("Label: " nop\n" b Label");
152
Reference Guide
Extended keywords
where \n (new line) separates each new assembler instruction. Note that you can define and use local labels in inline assembler instructions. For more information about inline assembler, see Mixing C and assembler, page 69.
__fiq This keyword declares a fast interrupt function. All interrupt functions must be compiled in ARM mode; use either the __arm keyword or the #pragma type_attribute=__arm directive to alter the default behavior if needed.
A function declared __fiq does not accept parameters and does not have a return value. Example
__fiq __arm void interrupt_function(void);
__interwork A function declared __interwork can be called from functions executing in either
__intrinsic The __intrinsic keyword is reserved for compiler internal use only.
__irq This keyword declares an interrupt function. All interrupt functions must be compiled in ARM mode; use either the __arm keyword or the #pragma type_attribute=__arm directive to alter the default behavior if needed.
A function declared __irq does not accept parameters and does not have a return value. Example
__irq __arm void interrupt_function(void);
153
__monitor 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. The __monitor keyword cannot be used for C++ constructors. The #pragma type_attribute directive can also be used. Avoid using the __monitor keyword on large functions, since the interrupt will otherwise be turned off for too long. For additional information, see the intrinsic functions __disable_interrupt, page 178, and __enable_interrupt, page 178. Read more about monitor functions on page 21.
__nested
The __nested keyword modifies the enter and exit code of an interrupt function to allow for nested interrupts. This allows interrupts to be enabled, which means new interrupts can be served inside an interrupt function, without overwriting the SPSR and return address in R14. Nested interrupts are only supported for __irq declared functions. For more information, see Nested interrupts, page 18. Example
__irq __nested __arm void interrup_handler(void);
__no_init
The __no_init keyword is used for suppressing initialization of a variable at system startup. The __no_init keyword is placed in front of the type. In this example, settings is placed in the non-initialized segment DATA_N:
__no_init int settings[10];
The #pragma object_attribute directive can also be used. The following declaration is equivalent to the previous one:
#pragma object_attribute=__no_init int settings[10];
154
Reference Guide
Extended keywords
__ramfunc This keyword makes a function execute in RAM. Two code segments will be created:
one for the RAM execution, and one for the ROM initialization. If a function declared __ramfunc tries to access ROM, the compiler will issue a warning. This behavior is intended to simplify the creation of upgrade routines, for instance, rewriting parts of flash memory. If this is not why you have declared the function __ramfunc, you may safely ignore or disable these warnings. Functions declared __ramfunc are by default stored in the segment named CODE_I. See the chapter Segment reference.
__root The __root attribute can be used on either a function or a variable to ensure that, when
the module containing the function or variable is linked, the function or variable is also included, whether or not it is referenced by the rest of the program. By default, only the part of the runtime library calling main and any interrupt vectors are root. All other functions and variables are included in the linked output only if they are referenced by the rest of the program. The __root keyword is placed in front of the type, for example to place settings in non-volatile memory:
__root int settings[10];
The #pragma object_attribute directive can also be used. The following declaration is equivalent to the previous one:
#pragma object_attribute=__root int settings[10];
__swi This keyword declares a software interrupt function. All interrupt functions must be compiled in ARM mode; use either the __arm keyword or the #pragma type_attribute=__arm directive to alter the default behavior if needed.
A function declared __swi accepts arguments and return values. The __swi keyword also expects a software interrupt number which is specified with the #pragma swi_number=number directive. A __swi function can for example be declared in the following way:
#pragma swi_number=0x23 __swi __arm int swi_function(int a, int b);
The swi_number is used as an argument to the generated assembler SWI instruction, and can be used to select one software interrupt function in a system containing several such functions.
155
Software interrupt functions follow the same calling convention regarding parameters and return values as an ordinary function. Four registers (R0R3) are used for passing parameters to a software interrupt function, and one or two registers (R0R1) are used for the return values. However, software interrupt functions cannot use the stack in the same way as an ordinary function. When an interrupt occurs, the processor switches to supervisor mode where the supervisor stack is used. Arguments can therefore not be passed on the stack if the program is not running in supervisor mode previous to the interrupt. As a consequence only the four registers R0R3 can be used for passing parameters.
__thumb This keyword makes a function execute in Thumb mode. Unless the function is also declared __interwork, the function declared __thumb can only be called from
functions that also execute in Thumb mode. A function declared __thumb cannot be declared __arm. Example
__thumb int func2(void);
156
Reference Guide
Pragma directives
This chapter describes the pragma directives of the ARM IAR C/C++ Compiler. The pragma directives control the behavior of the compiler, for example how it allocates memory, whether it allows extended keywords, and whether it outputs warning messages. The pragma directives are preprocessed, which means that macros are substituted in a pragma directive. The pragma directives are always enabled in the compiler. They are consistent with ISO/ANSI C and are very useful when you want to make sure that the source code is portable.
#pragma bitfields #pragma data_alignment #pragma diag_default #pragma diag_error #pragma diag_remark #pragma diag_suppress #pragma diag_warning #pragma include_alias #pragma inline #pragma language #pragma location #pragma message
Controls the order of bitfield members Gives a variable a higher (more strict) alignment Changes the severity level of diagnostic messages Changes the severity level of diagnostic messages Changes the severity level of diagnostic messages Suppresses diagnostic messages Changes the severity level of diagnostic messages Specifies an alias for an include file Inlines a function Controls the IAR language extensions Specifies the absolute address of a variable Prints a message
#pragma object_attribute Changes the definition of a variable or a function #pragma optimize #pragma pack
Table 37: Pragma directives summary
Specifies type and level of optimization Specifies the alignment of structures and union members
157
Pragma directive
Description
#pragma required #pragma rtmodel #pragma segment #pragma swi_number #pragma type_attribute #pragma vector
Ensures that a symbol which is needed by another symbol is present in the linked output Adds a runtime model attribute to the module Declares a segment name to be used by intrinsic functions Sets the interrupt number of a software interrupt function Changes the declaration and definitions of a variable or function Specifies the vector of an interrupt function
Note: For portability reasons, the pragma directives alignment, baseaddr, codeseg, constseg, dataseg, function, memory, and warnings are recognized but will give a diagnostic message. It is important to be aware of this if you need to port existing code that contains any of those pragma directives.
or
#pragma pragmaname = pragmavalue
The #pragma bitfields directive controls the order of bitfield members. By default, the ARM IAR C/C++ Compiler places bitfield members from the least significant bit to the most significant bit in the container type. Use the #pragma bitfields=reversed directive to place the bitfield members from the most significant to the least significant bit. This setting remains active until you turn it off again with the #pragma bitfields=default directive.
Use this pragma directive to give a variable a higher (more strict) alignment than it would otherwise have. It can be used on variables with static and automatic storage duration.
158
Reference Guide
Pragma directives
The value of the constant expression must be a power of two (1, 2, 4, etc.). When you use #pragma data_alignment on variables with automatic storage duration, there is an upper limit on the allowed alignment for each function, determined by the calling convention used.
Changes the severity level back to default, or as defined on the command line for the diagnostic messages with the specified tags. See the chapter Diagnostics for more information about diagnostic messages. Example
#pragma diag_default=Pe117
Changes the severity level to error for the specified diagnostics. See the chapter Diagnostics for more information about diagnostic messages. Example
#pragma diag_error=Pe117
Changes the severity level to remark for the specified diagnostics. For example:
#pragma diag_remark=Pe177
See the chapter Diagnostics for more information about diagnostic messages.
Suppresses the diagnostic messages with the specified tags. For example:
#pragma diag_suppress=Pe117,Pe177
See the chapter Diagnostics for more information about diagnostic messages.
159
Changes the severity level to warning for the specified diagnostics. For example:
#pragma diag_warning=Pe826
See the chapter Diagnostics for more information about diagnostic messages.
#pragma include_alias #pragma include_alias "orig_header" "subst_header" #pragma include_alias <orig_header> <subst_header>
The #pragma include_alias directive makes it possible 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. The parameter subst_header is used for specifying an alias for orig_header. This pragma directive must appear before the corresponding #include directives and subst_header must match its corresponding #include directive exactly. Example
#pragma include_alias <stdio.h> <C:\MyHeaders\stdio.h> #include <stdio.h>
This example will substitute the relative file stdio.h with a counterpart located according to the specified path.
The #pragma inline directive advises the compiler that the function whose declaration follows immediately after the directive should be inlinedthat is, expanded into the body of the calling function. Whether the inlining actually takes place is subject to the compilers heuristics. This is similar to the C++ keyword inline, but has the advantage of being available in C code. Specifying #pragma inline=forced disables the compilers heuristics and forces the inlining. If the inlining fails for some reason, for example if it cannot be used with the function type in question (like printf), an error message is emitted.
160
Reference Guide
Pragma directives
The #pragma language directive is used for turning on the IAR language extensions or for using the language settings specified on the command line:
extended
Turns on the IAR language extensions and turns off the --strict_ansi command line option. Uses the settings specified on the command line.
default
The #pragma location directive specifies the locationthe absolute addressof the variable whose declaration follows the pragma directive. For example:
#pragma location=0xFFFF0400 char PORT1; /* PORT1 is located at address 0xFFFF0400 */
The directive can also take a string specifying the segment placement for either a variable or a function, for example:
#pragma location="foo"
For additional information and examples, see Located data, page 33.
Makes the compiler print a message on stdout when the file is compiled. For example:
#ifdef TESTING #pragma message("Testing") #endif
The #pragma object_attribute directive affects the definition of the identifier that follows immediately after the directive. The object is modified, not its type. The __no_init extended keyword can be used with #pragma object_attribute for a variable. It suppresses initialization of the variable at startup. The __root extended keyword can be used with #pragma object_attribute for a function or variable. It ensures that a function or data object is included in the object code even if not referenced The __ramfunc extended keyword can be used with #pragma object_attribute for a function. It makes the function execute in RAM.
161
Example In the following example, the variable bar is placed in the non-initialized segment:
#pragma object_attribute=__no_init char bar;
Unlike the directive #pragma type_attribute that specifies the storing and accessing of a variable, it is not necessary to specify an object attribute in declarations. The following example declares bar without a #pragma object_attribute:
__no_init char bar;
Turns off code motion Turns off common sub-expression elimination Turns off function inlining Turns off type-based alias analysis Turns off loop unrolling
The #pragma optimize directive is used for decreasing the optimization level, or for turning off some specific optimizations. This pragma directive only affects the function that follows immediately after the directive. Note that it is not possible to optimize for speed and size at the same time. Only one of the s and z tokens can be used. It is also not possible to use macros embedded in this pragma directive. Any such macro will not get 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.
162
Reference Guide
Pragma directives
Example
#pragma optimize=s 9 int small_and_used_often() { ... } #pragma optimize=z 9 int big_and_seldom_used() { ... }
#pragma pack #pragma pack([[{push|pop},][name,]][n]) n name Packing alignment, one of: 1, 2, 4, 8, or 16 Pushed or popped alignment label
The #pragma pack directive is used for specifying the alignment of structures and union members.
pack(n) sets the structure alignment to n. The pack(n) only affects declarations of structures following the pragma directive and to the next #pragma pack or end of file. pack() resets the structure alignment to default. pack(push [,name] [,n]) pushes the current alignment with the label name and sets alignment to n. Note that both name and n are optional. pack(pop [,name] [,n]) pops to the label name and sets alignment to n. Note that both name and n are optional.
If name is omitted, only top alignment is removed. If n is omitted, alignment is set to the value popped from the stack. Note that accessing an object that is not aligned at its correct alignment requires code that is both larger and slower than the code needed to access the same kind of object when aligned correctly. If there are many accesses to such fields in the program, it is usually better to construct the correct values in a struct that is not packed, and access this instead. Also, special care is needed when creating and using pointers to misaligned fields. For direct access to such fields in a packed struct, the compiler will emit the correct (slower and larger) code when needed. However, when such a field is accessed through a pointer to the field, the normal (smaller and faster) code for accessing the type of the field is used, which will, in the general case, not work.
163
Example 1 This example declares a structure without using the #pragma pack directive:
struct First { char alpha; short beta; };
In this example, the structure First is not packed and has the following memory layout:
alpha beta
1 byte
1 byte
2 bytes
Note that one pad byte has been added. Example 2 This example declares a similar structure using the #pragma pack directive:
#pragma pack(1) struct FirstPacked { char alpha; short beta; }; #pragma pack()
In this example, the structure FirstPacked is packed and has the following memory layout:
alpha beta
1 byte
2 bytes
Example 3 This example declares a new structure, Second, that contains the structure FirstPacked declared in the previous example. The declaration of Second is not placed inside a #pragma pack block:
struct Second {
164
Reference Guide
Pragma directives
1 byte
2 bytes
1 byte
2 bytes
Note that the structure FirstPacked will use the memory layout, size, and alignment described in example 2. The alignment of the member gamma is 2, which means that alignment of the structure Second will become 2 and one pad byte will be be added.
Use the #pragma required directive to ensure that a symbol which is needed by another symbol is present in the linked output. The symbol can be any statically linked function or variable, and the pragma directive must be placed immediately before a symbol definition. 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. Example
void * const myvar_entry @ "MYSEG" = &myvar; ... #pragma required=myvar_entry long myvar;
Use the #pragma rtmodel directive to add a runtime model attribute to a module. Use a text string to specify key and value. This pragma directive is useful to enforce 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 value, or the special value *. Using the special value * is equivalent to not defining the attribute at all. It can, however, be useful to state explicitly that the module can handle any runtime model. A module can have several runtime model definitions.
165
Note: The predefined compiler runtime model attributes start with a double underscore. In order to avoid confusion, this style must not be used in the user-defined attributes. Example
#pragma rtmodel="I2C","ENABLED"
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. For more information about runtime model attributes and module consistency, see Checking module consistency, page 63.
The #pragma segment directive declares a segment name that can be used by the intrinsic functions __segment_begin and __segment_end. Example
#pragma segment="MYSEG"
See also __sfb, __segment_begin, page 180. For more information about segments and segment parts, see the chapter Placing code and data.
The #pragma swi_number directive is used in conjunction with the __swi extended keyword. It is used as an argument to the generated SWI assembler instruction, and can be used for selecting one software interrupt function in a system containing several such functions. For additional information, see Software interrupts, page 19.
The following #pragma type_attribute directive affects the code generation of the next function that follows immediately after the pragma directive:
__arm __fiq __interwork __irq
Makes a function execute in ARM mode. Declares a fast interrupt function. Makes a function execute in either ARM or Thumb mode. Declares an interrupt function.
166
Reference Guide
Pragma directives
Specifies a monitor function. Declares a software interrupt function. Makes a function execute in Thumb mode.
For interrupt functions, use the #pragma vector directive to specify the exception vector. Example In the following example, thumb-mode code is generated for the function foo.
#pragma type_attribute=__thumb void foo(void) { }
The following declaration, which use the corresponding extended keyword, is equivalent. See the chapter Extended keywords for more details.
__thumb void foo(void); { }
The #pragma vector directive specifies the vector(s) of an interrupt function whose declaration follows the pragma directive. Example
#pragma vector=0x14 __irq __arm void my_handler(void);
167
168
Reference Guide
The preprocessor
This chapter gives a brief overview of the preprocessor, including reference information about the different preprocessor directives, symbols, and other related information.
Predefined preprocessor symbols. These symbols allow you to inspect the compile-time environment, for example the time and date of compilation. Some of the symbols take arguments and perform more advanced operations than just inspecting the compile-time environment. For details, see Predefined symbols, page 169. User-defined preprocessor symbols. Use the option -D to define your own preprocessor symbols, see -D, page 131. Preprocessor extensions. There are several preprocessor extensions, for example many pragma directives; for more information, see the chapter Pragma directives in this guide. For information about other extensions, see Preprocessor extensions, page 175. Preprocessor output. Use the option --preprocess to direct preprocessor output to a named file, see --preprocess, page 145. Implementation-defined behavior. Some parts listed by the ISO/ANSI standard are implementation-defined, for example the character set used in the preprocessor directives and inclusion of bracketed and quoted filenames. To read more about this, see Preprocessing directives, page 194.
Predefined symbols
This section first summarizes all predefined symbols and then provides detailed information about each symbol.
169
Predefined symbols
Accesses the alignment of an object Identifies the processor core in use Identifies the processor core in use Identifies the processor core in use Identifies the processor core in use Identifies the processor core in use Identifies type of floating-point unit Identifies the name of the file being compiled. If the file is a header file, the name of the file that includes the header file is identified. Identifies the chip core in use Determines whether the compiler runs in C++ mode* Identifies the processor mode in use Determines the date of compilation* Determines whether the compiler runs in C++ mode* Identifies the name of the file being compiled* Expands into a string with the function name as context Expands into a string with the function name as context Identifies the IAR compiler platform Identifies the ARM IAR C/C++ Compiler Determines the current source line number* Identifies the byte order in use Can be used in preprocessor defines and has the equivalent effect as the pragma directive Expands into a string with the function name, including parameter types and return type, as context Identifies ISO/ANSI Standard C* Identifies the version of ISO/ANSI Standard C in use* Identifies the target processor of the IAR compiler in use
__CORE__ __cplusplus __CPU_MODE__ __DATE__ __embedded_cplusplus __FILE__ __func__ __FUNCTION__ __IAR_SYSTEMS_ICC__ __ICCARM__ __LINE__ __LITTLE_ENDIAN__ _Pragma() __PRETTY_FUNCTION__ __STDC__ __STDC_VERSION__ __TID__
Table 38: Predefined symbols summary
170
Reference Guide
The preprocessor
Predefined symbol
Identifies
__TIME__ __VER__
Table 38: Predefined symbols summary
*
Determines the time of compilation* Identifies the version number of the IAR compiler in use
__ALIGNOF__() The __ALIGNOF__ operator is used to access the alignment of an object. It takes one of
two forms:
When the compiler is generating code for an ARM core, the corresponding of these predefined symbols is defined. Subsets of the current core are also defined but with a smaller value. For example:
#if defined(__ARM5__) #include "intrinsics.h" #define my_own_CLZ_implementation(VAL) __CLZ(VAL) #endif
__ARMVFP__ Enabling vector floating-point (VFP) code generation will set the macro __ARMVFP__
to a value of 1 for VFPv1, and a value of 2 for VFPv2. If VFP code generation is disabled (default), the macro will be undefined.
__BASE_FILE__ Use this symbol to identify which file is currently being compiled. This symbol expands
to the name of that file, unless the file is a header file. In that case, the name of the file that includes the header file is identified. See also, __FILE__, page 172.
171
Predefined symbols
__CORE__ This predefined symbol expands to a number representing the core the compiler is
generating code for. Currently the defines in the following example can be used for checking if a certain core level is used or not:
#include "intrinsics.h" #if __CORE__ >= __ARM5__ //__CLZ is already declared #else #define __CLZ(VAL) my_own_CLZ_implementation(VAL) #endif
__cplusplus This predefined symbol expands to the number 199711L when the compiler runs in any
of the C++ modes. When the compiler runs in ISO/ANSI C mode, 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.
__CPU_MODE__ This predefined symbol expands to a number reflecting the default CPU mode in use:
Value CPU mode
1 2
Thumb ARM
__DATE__ Use this symbol to identify when the file was compiled. This symbol expands to the date of compilation, which is returned in the form "Mmm dd yyyy", for example "Jan 30 2002".
__embedded_cplusplus This predefined symbol expands to the number 1 when the compiler runs in any of the
C++ modes. When the compiler runs in ISO/ANSI C mode, the symbol is undefined.
__FILE__ Use this symbol to identify which file is currently being compiled. This symbol expands
172
Reference Guide
The preprocessor
__func__, __FUNCTION__ Use one of these symbols inside a function body to make it expand into a string with the
function name as context. This is useful for assertions and other trace utilities. These symbols require that language extensions are enabled, see -e, page 135. See also, __PRETTY_FUNCTION__, page 174.
__IAR_SYSTEMS_ICC__ This predefined symbol expands to a number that identifies the IAR compiler platform.
The current identifier is 6. 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.
__ICCARM__ This predefined symbol expands to the number 1 when the code is compiled with the
__LINE__ This predefined symbol expands to the current line number of the file currently being
compiled.
__LITTLE_ENDIAN__ This predefined symbol expands to the number 1when the code is compiled with the
little-endian byte order format, and 0 when the code is compiled with the big-endian byte order format.
_Pragma() The preprocessor operator _Pragma can be used in defines and has the equivalent effect of the #pragma directive. The syntax is: _Pragma("string")
where string follows the syntax for the corresponding pragma directive. For example:
#if NO_OPTIMIZE #define NOOPT _Pragma("optimize=2") #else #define NOOPT #endif
See the chapter Pragma directives. Note: The -e optionenable language extensionsis not required.
173
Predefined symbols
__PRETTY_FUNCTION__ Use this symbol inside a function body to make it expand into a string, with the function
name including parameter types and return type as context. The result might, for example, look like this:
"void func(char)"
This symbol is useful for assertions and other trace utilities. These symbols require that language extensions are enabled, see -e, page 135. See also, __func__, __FUNCTION__, page 173.
__STDC__ This predefined symbol expands to the number 1. This symbol can be tested with #ifdef to detect whether the compiler in use adheres to ISO/ANSI C.
This predefined symbol expands to 199409L. Note: This predefined symbol does not apply in EC++ mode.
A one-bit intrinsic flag (i) which is reserved for use by IAR A target-identifier (t) unique for each IAR compiler. For the ARM compiler, the target identifier is 79 A value (c) reserved for specifying different CPU cores. The value is derived from the setting of the --cpu option:
CPU core
Value
0 1 2 3
174
Reference Guide
The preprocessor
To find the value of the target identifier for the current compiler, execute:
printf("%ld",(__TID__ >> 8) & 0x7F)
Note: Because coding may change or functionality may be entirely removed in future versions, the use of __TID__ is not recommended. We recommend that you use the symbols __ICCARM__ and __CORE__ instead.
Expands to an integer representing the version number of the compiler. The value of the number is calculated in the following way:
(100 * the major version number + the minor version number)
In this example, 3 is the major version number and 34 is the minor version number.
Preprocessor extensions
The following section gives reference information about the extensions that are available in addition to the pragma directives and ISO/ANSI directives.
#warning message Use this preprocessor directive to produce messages. Typically this is useful for assertions and other trace utilities, similar to the way the ISO/ANSI standard #error
175
Preprocessor extensions
__VA_ARGS__ Variadic macros are the preprocessor macro equivalents of printf style functions.
Syntax
#define P(...) #define P(x,y,...) __VA_ARGS__ x + y + __VA_ARGS__
Here, __VA_ARGS__ will contain all variadic arguments concatenated, including the separating commas.
Example
#if DEBUG #define DEBUG_TRACE(...) printf(S,__VA_ARGS__) #else #define DEBUG_TRACE(...) #endif ... DEBUG_TRACE("The value is:%d\n",value);
176
Reference Guide
Intrinsic functions
This chapter gives reference information about the 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 in-line code, either as a single instruction or as a short sequence of instructions.
__CLZ __disable_interrupt __enable_interrupt __get_CPSR __MCR __MRC __no_operation __set_CPSR __sfb, __segment_begin __sfe, __segment_end __sfs, __segment_size __QADD __QDADD __QDSUB __QSUB
Table 41: Intrinsic functions summary
Generates a CLZ instruction Disables interrupts Enables interrupts Returns the value of the ARM CPSR (Current Program Status Register) Generates a coprocessor write instruction (MCR). Generates a coprocessor read instruction (MRC). Generates a NOP instruction Sets the value of the ARM CPSR (Current Program Status Register) Returns the start address of a segment Returns the end address of a segment Returns the size of a segment Generates a QADD instruction Generates a QDADD instruction Generates a QDSUB instruction Generates a QSUB instruction
To use intrinsic functions in an application, include the header file intrinsics.h. Note that the intrinsic function names start with double underscores, for example:
__segment_begin
177
In ARM mode, this intrinsic function disables interrupts by setting bits 6 and 7 of the CPSR register. In Thumb mode, this intrinsic function inserts a function call to a library function. Note: This intrinsic can only be used in supervisor mode.
In ARM mode, this intrinsic function enables interrupts by clearing bits 6 and 7 of the CPSR register. In Thumb mode, this intrinsic function inserts a function call to a library function. Note: This intrinsic can only be used in supervisor mode.
Returns the value of the ARM CPSR (Current Program Status Register). This intrinsic function requires ARM mode.
__MCR void _ _MCR(__ul coproc, __ul opcode_1, __ul src, __ul CRn, __ul CRm, __ul opcode_2);
Generates a coprocessor write instruction (MCR). A value will be written to a coprocessor register. The parameters coproc, opcode_1, CRn, CRm, and opcode_2 will be encoded in the MCR instruction operation code and must therefore be constants. The following parameters are used:
coproc opcode_1
178
Reference Guide
Intrinsic functions
The value to be written to the coprocessor. The coprocessor register to write to. Additional coprocessor register; set to zero if not used. Additional coprocessor-specific operation code; set to zero if not used.
opcode_2
__MRC unsigned long __MRC(__ul coproc, __ul opcode_1, __ul CRn, __ul CRm, __ul opcode_2);
Generates a coprocessor read instruction (MRC). Returns the value of the specified coprocessor register. The parameters coproc, opcode_1, CRn, CRm, and opcode_2 will be encoded in the MRC instruction operation code and must therefore be constants. The following parameters are used:
coproc opcode_1 CRn CRm
The coprocessor number 0..15. Coprocessor-specific operation code. The coprocessor register to write to. Additional coprocessor register; set to zero if not used. Additional coprocessor-specific operation code; set to zero if not used.
opcode_2
Sets the value of the ARM CPSR (Current Program Status Register). Only the control field is changed (bits 0-7). This intrinsic function requires ARM mode.
179
Returns the address of the first byte of the named segment. The named segment must be a string literal that has been declared earlier with the #pragma segment directive. See #pragma segment, page 166. Example
#pragma segment="MYSEG" ... segment_start_address = __segment_begin("MYSEG");
Returns the address of the first byte after the named segment. The named segment must be a string literal that has been declared earlier with the #pragma segment directive. See #pragma segment, page 166. Example
#pragma segment="MYSEG" ... segment_end_address = __segment_end("MYSEG");
Returns the size of the named segment. The named segment must be a string literal that has been declared earlier with the #pragma segment directive. See #pragma segment, page 166. Example
#pragma segment="MYSEG" ... segment_size = __segment_size("MYSEG");
Inserts a QADD instruction. This intrinsic function requires an ARM v5E architecture.
Inserts a QDADD instruction. This intrinsic function requires an ARM v5E architecture.
180
Reference Guide
Intrinsic functions
Inserts a QDSUB instruction. This intrinsic function requires an ARM v5E architecture.
Inserts a QSUB instruction. This intrinsic function requires an ARM v5E architecture.
181
182
Reference Guide
Library functions
This chapter gives an introduction to the C and C++ library functions. It also lists the header files used for accessing library definitions.
Introduction
The ARM IAR C/C++ Compiler comes with the IAR DLIB Library, which is a complete ISO/ANSI C and C++ library. This library also supports floating-point numbers in IEEE 754 format and it can be configured to include different levels of support for locale, file descriptors, multibytes, et cetera. For additional information, see the chapter The DLIB runtime environment. For detailed information about the library functions, see the online documentation supplied with the product. There is also keyword reference information for the DLIB library functions. To obtain reference information for a function, select the function name in the editor window and press F1. For additional information about library functions, see the chapter Implementation-defined behavior in this guide.
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 a number of 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.
183
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 library are reentrant, but the following functions and parts are not reentrant:
atexit heap functions strerror strtok I/O Needs static data Need static data for memory allocation tables Needs static data Designed by ISO/ANSI standard to need static data Every function that uses files in some way. This includes printf, scanf, getchar, and putchar. The functions sprintf and sscanf are not included.
In addition, some functions share the same storage for errno. These functions are not reentrant, since an errno value resulting from one of these functions can be destroyed by a subsequent use of the function before it has been read. Among these functions are:
exp, exp10, ldexp, log, log10, pow, sqrt, acos, asin, atan2, cosh, sinh, strtod, strtol, strtoul
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.
Adherence to a free-standing implementation of the ISO/ANSI standard for the programming language C. For additional information, see the chapterImplementation-defined behavior in this guide. Standard C library definitions, for user programs. Embedded C++ library definitions, for user programs. CSTARTUP, the module containing the start-up code. It is described in the The DLIB runtime environment chapter in this guide. Runtime support libraries; for example, low-level floating-point routines. Intrinsic functions, allowing low-level use of ARM features. See the chapter Intrinsic functions for more information.
184
Reference Guide
Library functions
C HEADER FILES
This section lists the header files specific to the DLIB library C definitions. Header files may additionally contain target-specific definitions; these are documented in the chapter IAR language extensions. The following table lists the C header files:
Header file Usage
assert.h ctype.h errno.h float.h iso646.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stdbool.h stddef.h stdio.h stdlib.h string.h time.h wchar.h wctype.h
Enforcing assertions when functions execute Classifying characters Testing error codes reported by library functions Testing floating-point type properties Using Amendment 1iso646.h standard header Testing integer type properties Adapting to different cultural conventions Computing common mathematical functions Executing non-local goto statements Controlling various exceptional conditions Accessing a varying number of arguments Adds support for the bool data type in C. Defining several useful types and macros Performing input and output Performing a variety of operations Manipulating several kinds of strings Converting between various time and date formats Support for wide characters Classifying wide characters
185
Embedded C++
The following table lists the Embedded C++ header files:
Header file Usage
complex exception fstream iomanip ios iosfwd iostream istream new ostream sstream stdexcept streambuf string strstream
Defining a class that supports complex arithmetic Defining several functions that control exception handling Defining several I/O streams classes that manipulate external files Declaring several I/O streams manipulators that take an argument Defining the class that serves as the base for many I/O streams classes Declaring several I/O streams classes before they are necessarily defined Declaring the I/O streams objects that manipulate the standard streams Defining the class that performs extractions Declaring several functions that allocate and free storage Defining the class that performs insertions Defining several I/O streams classes that manipulate string containers Defining several classes useful for reporting exceptions Defining classes that buffer I/O streams operations Defining a class that implements a string container Defining several I/O streams classes that manipulate in-memory character sequences
Defining several I/O stream classes that manipulate external files Declaring several I/O streams manipulators that take an argument Declaring the I/O streams objects that manipulate the standard streams Declaring several functions that allocate and free storage
algorithm
186
Reference Guide
Library functions
Header file
Description
deque functional hash_map hash_set iterator list map memory numeric queue set slist stack utility vector
A deque sequence container Defines several function objects A map associative container, based on a hash algorithm A set associative container, based on a hash algorithm Defines common iterators, and operations on iterators A doubly-linked list sequence container A map associative container Defines facilities for managing memory Performs generalized numeric operations on sequences A queue sequence container A set associative container A singly-linked list sequence container A stack sequence container Defines several utility components A vector sequence container
Enforcing assertions when functions execute Classifying characters Testing error codes reported by library functions Testing floating-point type properties Testing integer type properties Adapting to different cultural conventions Computing common mathematical functions Executing non-local goto statements Controlling various exceptional conditions
187
Header file
Usage
Accessing a varying number of arguments Defining several useful types and macros Performing input and output Performing a variety of operations Manipulating several kinds of strings Converting between various time and date formats
188
Reference Guide
Implementation-defined behavior
This chapter describes how the ARM IAR C/C++ Compiler handles the implementation-defined areas of the C language. ISO 9899:1990, the International Organization for Standardization standard Programming Languages - C (revision and redesign of ANSI X3.159-1989, American National Standard), changed by the ISO Amendment 1:1994, Technical Corrigendum 1, and Technical Corrigendum 2, contains an appendix called Portability Issues. The ISO appendix lists areas of the C language that ISO leaves open to each particular implementation. Note: The ARM IAR C/C++ Compiler adheres to a freestanding implementation of the ISO standard for the C programming language. This means that parts of a standard library can be excluded in the implementation.
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.
189
190
Reference Guide
Implementation-defined behavior
191
192
Reference Guide
Implementation-defined behavior
193
194
Reference Guide
Implementation-defined behavior
195
instantiate language location memory message module_name none no_pch NOTREACHED object_attribute once optimize pack __printf_args public_equ rtmodel __scanf_args system_include type_attribute VARARGS vector warnings
For a description of the pragma directives, see the chapter Pragma directives.
196
Reference Guide
Implementation-defined behavior
signal() (7.7.1.1)
The signal part of the library is not supported. Note: Low-level interface functions exist in the library, but will not perform anything. Use the template source code to implement application-specific signal handling. See Signal and raise, page 60.
Files (7.9.3)
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 File input and output, page 56.
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 File input and output, page 56.
197
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 File input and output, page 56.
%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 *.
198
Reference Guide
Implementation-defined behavior
Environment (7.10.4.4)
The set of available environment names and the method for altering the environment list is described in Environment interaction, page 59.
system() (7.10.4.5)
How the command processor works depends on how you have implemented the system function. See Environment interaction, page 59.
no error domain error range error file positioning error multi-byte encoding error unknown error error nnn
clock() (7.12.2.1)
From where the system clock starts counting depends on how you have implemented the clock function. See Time, page 61.
199
200
Reference Guide
A memory attribute controls the placement of the entity. There can be only one memory attribute. A type attribute controls aspects of the object visible to the surrounding context. There can be many different type attributes, and they must be included when the object is declared. An object attribute only has to be specified at the definition, but not at the declaration, of an object. The object attribute does not affect the object interface.
201
An absolute declared variable cannot have an initializer, which means the variable must also be __no_init or const declared. Example 2
void test(void) @ "MYOWNSEGMENT" { ...
Note that all segments, both user-defined and predefined, must be assigned a location, which is done in the linker command file.
_Pragma
For information about the preprocessor operator _Pragma, see _Pragma(), page 173.
Variadic macros
Variadic macros are the preprocessor macro equivalents of printf style functions. For more information, see __VA_ARGS__, page 176.
Inline assembler
Inline assembler can be used for inserting assembler instructions in the generated function. The syntax for inline assembler is:
asm("SWI 5");
In strict ISO/ANSI mode, the use of inline assembler is disabled. For more details about inline assembler, see Mixing C and assembler, page 69.
202
Reference Guide
__ALIGNOF__
For information about alignment, see Alignment, page 107, and __ALIGNOF__(), page 171.
Compound literals
To create compound literals you can use the following syntax:
/* Create a pointer to an anonymous array */ int *p = (int []) {1,2,3}; /* Create a pointer to an anonymous structX */ structX *px = &(structX) {5,6,7};
Note:
A compound literal can be modified unless it is declared const Compound literals are not supported in Embedded C++.
203
Without anonymous structure types, the union would have to be namedfor example uand the member elements accessed using the syntax obj.u.b.
struct str { int a; union { int b; int c; }; }; struct str obj;
This matches G.5.8 in the appendix of the ISO standard, ISO Portability Issues.
204
Reference Guide
struct str * GetAStr(int size) { return malloc(sizeof(struct str) + sizeof(unsigned long) * size); } void UseStr(struct str * s) { s->b[10] = 0; }
The struct will inherit the alignment requirements from all elements, including the alignment of the incomplete array. The array itself will not be included in the size of the struct. However, the alignment requirements will ensure that the struct will end exactly at the beginning of the array; this is known as padding. In the example, the alignment of struct str will be 4 and the size is also 4. (Assuming a processor where the alignment of unsigned long is 4.) The memory layout of struct str is described in the following figure.
pad byte
pad byte
pad byte
...
205
Example The following source file is only used in a debug build. (In a debug build, the NDEBUG preprocessor flag is undefined.) Since the entire contents of the file is conditionally compiled using the preprocessor, the translation unit will be empty when the application is compiled in release mode. Without this extension, this would be considered an error.
#ifndef NDEBUG void PrintStatusToTerminal() { /* Do something */ } #endif
206
Reference Guide
Example
enum { kOne, kTwo, };
207
A good way to convert this into a standard-compliant C program is to place a break; statement after the default: label.
Empty declarations
An empty declaration (a semicolon by itself) is allowed, but a remark is issued (provided that remarks are enabled). This is useful when preprocessor macros are used that could expand to nothing. Consider the following example. In a debug build, the macros DEBUG_ENTER and DEBUG_LEAVE could be defined to something useful. However, in a release build they could expand into nothing, leaving the ; character in the code:
void test() { DEBUG_ENTER(); do_something(); DEBUG_LEAVE(); }
208
Reference Guide
209
Repeated typedefs
Redeclarations of typedef that occur in the same scope are allowed, but a warning is issued.
Non-lvalue arrays
A non-lvalue array expression is converted to a pointer to the first element of the array when it is used.
210
Reference Guide
Diagnostics
This chapter 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
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 diagnostic, tag is a unique tag that identifies the diagnostic message, and message is a self-explanatory message, 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 in a named file.
Severity levels
The diagnostics 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 147.
Warning
A diagnostic that is produced when the compiler finds a programming error or omission which is of concern, but not so severe as to prevent the completion of compilation. Warnings can be disabled by use of the command-line option --no_warnings, see page 144.
211
Severity levels
Error
A diagnostic that is produced when the compiler has found 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 that is produced when the compiler has found a condition that not only prevents code generation, but which makes further processing of the source code pointless. After the diagnostic has been 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 has been a serious and unexpected failure due to a fault in the compiler. It is produced using the following form:
Internal error: message
where message is an explanatory message. If internal errors occur, they should be reported to your software distributor or IAR Technical Support. Include information enough to reproduce the problem, typically:
The product name The version number of the compiler, which can be seen in the header of the list files generated by the compiler Your license number The exact internal error message text The source file of the program that generated the internal error A list of the options that were used when the internal error occurred.
212
Reference Guide
Index
Index A
absolute location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 #pragma location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 absolute placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 algorithm (STL header file) . . . . . . . . . . . . . . . . . . . . . . . 186 alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 forcing stricter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 _ _ALIGNOF_ _() (predefined symbol) . . . . . . . . . . . . . . 171 anonymous structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 anonymous symbols, creating . . . . . . . . . . . . . . . . . . . . . . 203 applications building . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 initializing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 terminating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 architecture, ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv ARGFRAME (compiler function directive) . . . . . . . . . . . . 22 ARM architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Arm and Thumb code overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 ARM (CPU mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 _ _ARMVFP_ _ (predefined symbol) . . . . . . . . . . . . . . . . 171 _ _ARM4TM_ _ (predefined symbol) . . . . . . . . . . . . . . . 171 _ _ARM5_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . 171 _ _ARM5E_ _ (predefined symbol) . . . . . . . . . . . . . . . . . 171 _ _ARM5T_ _ (predefined symbol) . . . . . . . . . . . . . . . . . 171 _ _ARM5TM_ _ (predefined symbol) . . . . . . . . . . . . . . . 171 arrays implementation-defined behavior . . . . . . . . . . . . . . . . . 193 asm (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . . . 152 asm (inline assembler) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 assembler directives CFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 CODE16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 CODE32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 DC32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 ENDMOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 EQU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 MODULE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 PUBLIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 REQUIRE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 RSEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 RTMODEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 assembler instructions SWI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 assembler language interface . . . . . . . . . . . . . . . . . . . . . . . 69 creating skeleton code . . . . . . . . . . . . . . . . . . . . . . . . . . 72 assembler list file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 assembler routines, calling from C . . . . . . . . . . . . . . . . . . . 72 assembler, inline . . . . . . . . . . . . . . . . . . . . . . . . . 71, 100, 202 assert.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 assumptions (programming experience) . . . . . . . . . . . . . . . xv atomic operations, performing . . . . . . . . . . . . . . . . . . . . . 154 attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 auto variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1112 saving stack space . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
B
_ _BASE_FILE_ _ (predefined symbol) . . . . . . . . . . . . . . 171 big endian (byte order) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 bitfields data representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 implementation-defined behavior . . . . . . . . . . . . . . . . . 193 bitfields (pragma directive) . . . . . . . . . . . . . . . . . . . . 110, 158 bool (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 supported in C code . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 bool (data type), adding support for . . . . . . . . . . . . . . . . . 185 byte order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 big-endian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 little-endian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
213
C
_ _CORE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 172 _ _CPU_MODE_ _ (predefined symbol) . . . . . . . . . . . . . 172 C and C++ linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 C calling convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 C header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 call chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 callee-save registers, stored on stack . . . . . . . . . . . . . . . . . . 12 calling convention C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 calloc (standard library function) . . . . . . . . . . . . . . . . . . . . 13 cassert (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 cast operators in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . . 86 casting, of pointers and integers . . . . . . . . . . . . . . . . . . . . 112 cctype (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 cerrno (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 CFI (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 83 cfloat (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 187 char (data type), signed and unsigned . . . . . . . . . . . . 109, 130 characters, implementation-defined behavior . . . . . . . . . . 190 --char_is_signed (compiler option) . . . . . . . . . . . . . . . . . . 130 classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 CLIB documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 library object files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 climits (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 clocale (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 _ _close (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 cmath (library header file). . . . . . . . . . . . . . . . . . . . . . . . . 187 code ARM and Thumb, overview. . . . . . . . . . . . . . . . . . . . . . 15 excluding when linking . . . . . . . . . . . . . . . . . . . . . . . . . 66 placement of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
placement of startup code . . . . . . . . . . . . . . . . . . . . . . . 33 Code motion (compiler option) . . . . . . . . . . . . . . . . . . . . . . 94 code motion, disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 code pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 CODE (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 118 CODE_I (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 CODE_ID (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 CODE16 (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 71 CODE32 (assembler directive) . . . . . . . . . . . . . . . . . . . . . . 71 common sub-expression elimination, disabling . . . . . . . . 142 Common-subexpr elimination (compiler option) . . . . . . . . 93 compiler environment variables . . . . . . . . . . . . . . . . . . . . 127 compiler error return codes . . . . . . . . . . . . . . . . . . . . . . . . 127 compiler listing, generating. . . . . . . . . . . . . . . . . . . . . . . . 139 compiler object file including debug information . . . . . . . . . . . . . . . . 131, 146 specifying filename . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 compiler options Code motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Common-subexpr elimination . . . . . . . . . . . . . . . . . . . . 93 Function inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Instruction scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Loop unrolling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 specifying parameters . . . . . . . . . . . . . . . . . . . . . . . . . 126 Static clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Type-based alias analysis . . . . . . . . . . . . . . . . . . . . . . . . 94 typographic convention . . . . . . . . . . . . . . . . . . . . . . . xviii -D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 -e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 -f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 -I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 -l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73, 139 -o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 -r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131, 146 -s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 -z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 --char_is_signed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
214
Reference Guide
Index
--cpu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 --cpu_mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 --debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131, 146 --dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 --diagnostics_tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 --diag_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 --diag_remark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 --diag_suppress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 --diag_warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 --dlib_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 --ec++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 --eec++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 --enable_multibytes . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 --endian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 --fpu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 --header_context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 --interwork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 --library_module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 --migration_preprocessor_extensions. . . . . . . . . . . . . . 140 --module_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 --no_clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 --no_code_motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 --no_cse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 --no_inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142143 --no_scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 --no_tbaa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 --no_typedefs_in_diagnostics . . . . . . . . . . . . . . . . . . . 143 --no_unroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 --no_warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 --no_wrap_diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . 144 --omit_types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 --only_stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 --preinclude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 --preprocess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 --public_equ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 --remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 --require_prototypes. . . . . . . . . . . . . . . . . . . . . . . . . . . 147 --segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 --separate_cluster_for_initialized_variables . . . . . . . . . 148
--silent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 --stack_align . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 --strict_ansi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 --warnings_affect_exit_code . . . . . . . . . . . . . . . . 127, 149 --warnings_are_errors . . . . . . . . . . . . . . . . . . . . . . . . . 149 compiler version number . . . . . . . . . . . . . . . . . . . . . . . . . 175 compiling, from the command line . . . . . . . . . . . . . . . . . . . . 4 complex numbers, supported in Embedded C++ . . . . . . . . . 86 complex (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 compound literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 computer style, typographic convention . . . . . . . . . . . . . xviii configuration basic project settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 configuration symbols, in library configuration files. . . . . . 49 consistency, module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 const_cast (cast operator) . . . . . . . . . . . . . . . . . . . . . . . . . . 86 conventions, typographic . . . . . . . . . . . . . . . . . . . . . . . . xviii copy initialization, of segments . . . . . . . . . . . . . . . . . . . . . . 34 copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii --cpu (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 CPU modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 CPU variant, specifying on command line . . . . . . . . . . . . 130 --cpu_mode (compiler option) . . . . . . . . . . . . . . . . . . . . . 130 _ _cpu_mode (runtime model attribute) . . . . . . . . . . . . . . . 65 csetjmp (library header file) . . . . . . . . . . . . . . . . . . . . . . . 187 csignal (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 CSTACK (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 See also stack cstartup, customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 cstartup, implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 cstdarg (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 188 cstddef (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 188 cstdio (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 188 cstdlib (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 188 cstring (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 188 ctime (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 188 ctype.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185
215
customization _ _low_level_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 C++ calling convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 features excluded from EC++ . . . . . . . . . . . . . . . . . . . . 85 See also Embedded C++ and Extended Embedded C++ terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii C++ header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185186 C-SPY STL container support . . . . . . . . . . . . . . . . . . . . . . . . . . 88 C-SPY, low-level interface . . . . . . . . . . . . . . . . . . . . . . . . . 62 C_INCLUDE (environment variable) . . . . . . . . . . . . 127, 138
D
data alignment of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 excluding when linking . . . . . . . . . . . . . . . . . . . . . . . . . 66 placement of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 data pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 data representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 data storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 DATA_AC (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 data_alignment (pragma directive) . . . . . . . . . . . . . . . . . . 158 DATA_AN (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_C (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_I (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_ID (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 DATA_N (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 DATA_Z (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 _ _DATE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 172 date (library function), configuring support for . . . . . . . . . . 61 DC32 (assembler directive). . . . . . . . . . . . . . . . . . . . . . . . . 71 --debug (compiler option) . . . . . . . . . . . . . . . . . . . . . 131, 146 debug information, including in object file . . . . . . . . 131, 146 declaration, of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
declarators, implementation-defined behavior . . . . . . . . . 194 delete (keyword) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 --dependencies (compiler option) . . . . . . . . . . . . . . . . . . . 132 deque (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 187 destructors and interrupts, using . . . . . . . . . . . . . . . . . . . . . 89 diagnostic messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 classifying as errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 classifying as remarks . . . . . . . . . . . . . . . . . . . . . . . . . 133 classifying as warnings . . . . . . . . . . . . . . . . . . . . . . . . 134 disabling warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 disabling wrapping of . . . . . . . . . . . . . . . . . . . . . . . . . 144 enabling remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 listing all used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 suppressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 --diagnostics_tables (compiler option) . . . . . . . . . . . . . . . 134 diag_default (pragma directive) . . . . . . . . . . . . . . . . . . . . 159 --diag_error (compiler option) . . . . . . . . . . . . . . . . . . . . . 133 diag_error (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 159 --diag_remark (compiler option) . . . . . . . . . . . . . . . . . . . . 133 diag_remark (pragma directive) . . . . . . . . . . . . . . . . . . . . 159 --diag_suppress (compiler option) . . . . . . . . . . . . . . . . . . 134 diag_suppress (pragma directive) . . . . . . . . . . . . . . . . . . . 159 --diag_warning (compiler option) . . . . . . . . . . . . . . . . . . . 134 diag_warning (pragma directive) . . . . . . . . . . . . . . . . . . . 160 DIFUNCT (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 directives function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 157 disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii DLIB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8, 184 documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 --dlib_config (compiler option) . . . . . . . . . . . . . . . . . . . . . 135 document conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . xviii documentation, library . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 double (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 dynamic initialization . . . . . . . . . . . . . . . . . . . . . . . 4647, 51 in Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 dynamic memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
216
Reference Guide
Index
E
--ec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 135 EC++ header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 --eec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 136 Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 absolute location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 declaring functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 differences from C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 dynamic initialization in . . . . . . . . . . . . . . . . . . . . . . . . 35 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 function linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 language extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 static member variables . . . . . . . . . . . . . . . . . . . . . . . . . 35 --enable_multibytes (compiler option) . . . . . . . . . . . . . . . 136 --endian (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 136 _ _endian (runtime model attribute) . . . . . . . . . . . . . . . . . . 65 ENDMOD (assembler directive) . . . . . . . . . . . . . . . . . . . . . 66 enumerations, implementation-defined behavior. . . . . . . . 193 enum, data representation . . . . . . . . . . . . . . . . . . . . . . . . . 109 environment implementation-defined behavior . . . . . . . . . . . . . . . . . 190 environment variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 C_INCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127, 138 QCCARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 EQU (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 146 errno.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185 error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 classifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 error return codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 exception handling, missing from Embedded C++ . . . . . . . 85 exception stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 exception vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 exception (library header file) . . . . . . . . . . . . . . . . . . . . . . 186 experience, programming . . . . . . . . . . . . . . . . . . . . . . . . . . xv export keyword, missing from Extended EC++ . . . . . . . . . 88 Extended Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . 86 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
standard template library (STL) . . . . . . . . . . . . . . . . . . 186 extended keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 asm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 _ _arm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 _ _fiq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 _ _interwork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 _ _intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 _ _irq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 using in pragma directives. . . . . . . . . . . . . . . . . . . . 167 _ _monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 using in pragma directives. . . . . . . . . . . . . . . . . . . . 167 _ _nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 _ _no_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103, 154 _ _ramfunc . . . . . . . . . . . . . . . . . . . . . . . . . . . 16, 154155 _ _root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 _ _swi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 _ _thumb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
F
-f (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 fast interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 fatal error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 _ _FILE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 172 file dependencies, tracking . . . . . . . . . . . . . . . . . . . . . . . . 132 file paths, specifying for #include files . . . . . . . . . . . . . . . 138 filename, of object file . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 float (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 floating-point constants hexadecimal notation . . . . . . . . . . . . . . . . . . . . . . . . . . 209 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 floating-point format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 implementation-defined behavior . . . . . . . . . . . . . . . . . 192
217
special cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 32-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 64-bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 floating-point unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 float.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185 formats floating-point values . . . . . . . . . . . . . . . . . . . . . . . . . . 110 standard IEEE (floating point) . . . . . . . . . . . . . . . . . . . 110 _formatted_write (library function) . . . . . . . . . . . . . . . . . . 45 --fpu (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 fragmentation, of heap memory . . . . . . . . . . . . . . . . . . . . . 13 free (standard library function) . . . . . . . . . . . . . . . . . . . . . . 13 fstream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 fstream.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 186 _ _func_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 173 FUNCALL (compiler function directive) . . . . . . . . . . . . . . 22 _ _FUNCTION_ _ (predefined symbol) . . . . . . . . . . . . . . 173 function directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 function execution, in RAM . . . . . . . . . . . . . . . . . . . . . . . . 16 Function inlining (compiler option) . . . . . . . . . . . . . . . . . . 94 function inlining, disabling . . . . . . . . . . . . . . . . . . . . 142143 function prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 function type information omitting in object output . . . . . . . . . . . . . . . . . . . . . . . 145 FUNCTION (compiler function directive) . . . . . . . . . . . . . 22 functional (STL header file) . . . . . . . . . . . . . . . . . . . . . . . 187 functions declaring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 extended keywords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69, 100 monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 omitting type info . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 placing in segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 recursive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 storing data on stack . . . . . . . . . . . . . . . . . . . . . . 1213
G
getenv (library function), configuring support for . . . . . . . . 59 getzone (library function), configuring support for . . . . . . . 61 glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv guidelines, reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
H
hash_map (STL header file) . . . . . . . . . . . . . . . . . . . . . . . 187 hash_set (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . 187 header files C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185186 EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 special function registers . . . . . . . . . . . . . . . . . . . . . . . 102 stdbool.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109, 185 stddef.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 using as templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 --header_context (compiler option) . . . . . . . . . . . . . . . . . . 137 heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 changing default size . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3233 storing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 HEAP (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32, 120 hidden parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 hints optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
I
-I (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 IAR Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 _ _IAR_SYSTEMS_ICC_ _ (predefined symbol) . . . . . . 173
218
Reference Guide
Index
_ _ICCARM_ _ (predefined symbol) . . . . . . . . . . . . . . . . 173 ICODE (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 123 identifiers, implementation-defined behavior . . . . . . . . . . 190 IEEE format, floating-point values . . . . . . . . . . . . . . . . . . 110 implementation, cstartup . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 implementation-defined behavior . . . . . . . . . . . . . . . . . . . 189 intrinsics.h (header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 177 inheritance, in Embedded C++ . . . . . . . . . . . . . . . . . . . . . . 85 initialization, dynamic . . . . . . . . . . . . . . . . . . . . . . 4647, 51 INITTAB (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 inline assembler . . . . . . . . . . . . . . . . . . . . . . . . . 71, 100, 202 See also assembler language interface inline (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 160 inlining of functions, in compiler . . . . . . . . . . . . . . . . . . . . 94 Instruction scheduling (compiler option) . . . . . . . . . . . . . . 96 instruction set, ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv int (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 implementation-defined behavior . . . . . . . . . . . . . . . . . 192 intptr_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 ptrdiff_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 size_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 uintptr_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 internal error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 interrupt functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 fast interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 installing in vector table . . . . . . . . . . . . . . . . . . . . . . . . . 20 INTVEC segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 nested interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 placement in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 software interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 interrupt handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 interrupt vectors, specifying with pragma directive. . . . . . 167 interrupts disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 disabling during function execution . . . . . . . . . . . . . . . . 21
processor state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 interrupts and EC++ destructors, using . . . . . . . . . . . . . . . . 89 interworking code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 generating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 intptr_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 _ _intrinsic (extended keyword) . . . . . . . . . . . . . . . . . . . . 153 intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 _ _CLZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _disable_interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _enable_interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _get_CPSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _MCR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _MRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 _ _no_operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 _ _QADD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _QDADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _QDSUB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 _ _QSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 _ _segment_begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _segment_end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _segment_size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _set_CPSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 _ _sfb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _sfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _sfs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 INTVEC (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 123 iomanip (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 iomanip.h (library header file) . . . . . . . . . . . . . . . . . . . . . 186 ios (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 iosfwd (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 186 iostream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 iostream.h (library header file) . . . . . . . . . . . . . . . . . . . . . 186 _ _irq (extended keyword) using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 167 IRQ_STACK (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . 124 ISO/ANSI C C++ features excluded from EC++ . . . . . . . . . . . . . . . . 85
219
language extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 specifying strict usage . . . . . . . . . . . . . . . . . . . . . . . . . 149 iso646.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 istream (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 186 iterator (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 187
K
keywords, extended. . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 151
L
-l (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 73, 139 _ _LITTLE_ENDIAN_ _ (predefined symbol) . . . . . . . . . 173 language extensions descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Embedded C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 language (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . 161 libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 runtime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 standard template library . . . . . . . . . . . . . . . . . . . . . . . 186 library configuration file option for specifying . . . . . . . . . . . . . . . . . . . . . . . . . . 135 library configuration file, modifying . . . . . . . . . . . . . . . . . . 50 library documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 library features, missing from Embedded C++ . . . . . . . . . . 86 library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 choosing printf formatter . . . . . . . . . . . . . . . . . . . . . . . . 45 choosing scanf formatter . . . . . . . . . . . . . . . . . . . . . . . . 46 choosing sprintf formatter . . . . . . . . . . . . . . . . . . . . . . . 45 choosing sscanf formatter . . . . . . . . . . . . . . . . . . . . . . . 46 remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 _ _close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _lseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
_ _write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 library modules, creating . . . . . . . . . . . . . . . . . . . . . . . . . 140 library object files CLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 --library_module (compiler option) . . . . . . . . . . . . . . . . . 140 limits.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 _ _LINE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 173 linkage, C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 linker command files contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 customizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 2934 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 using the -Z command . . . . . . . . . . . . . . . . . . . . . . . . . . 28 viewing default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 linking, from the command line . . . . . . . . . . . . . . . . . . . . . . 4 list (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 listing, generating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 literals, compound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 literature, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . xvii little endian (byte order) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 locale.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 location (pragma directive) . . . . . . . . . . . . . . . . . . 3536, 161 LOCFRAME (compiler function directive) . . . . . . . . . . . . 22 long (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Loop unrolling (compiler option) . . . . . . . . . . . . . . . . . . . . 93 loop unrolling, disabling . . . . . . . . . . . . . . . . . . . . . . . . . . 143 loop-invariant expressions. . . . . . . . . . . . . . . . . . . . . . . . . . 94 low-level processor operations . . . . . . . . . . . . . . . . . . . . . 177 _ _low_level_init, customizing . . . . . . . . . . . . . . . . . . . . . . 53 _ _lseek (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57
M
macros, variadic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 malloc (standard library function) . . . . . . . . . . . . . . . . . . . . 13 map (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 math.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185
220
Reference Guide
Index
memory allocating in Embedded C++ . . . . . . . . . . . . . . . . . . . . . 13 dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 RAM, saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 releasing in Embedded C++ . . . . . . . . . . . . . . . . . . . . . . 13 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 stack, saving. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 used by executing functions . . . . . . . . . . . . . . . . . . . . . . 11 used by global or static variables . . . . . . . . . . . . . . . . . . 11 memory management, type-safe . . . . . . . . . . . . . . . . . . . . . 85 memory (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 187 message (pragma directive). . . . . . . . . . . . . . . . . . . . . . . . 161 --migration_preprocessor_extensions (compiler option) . . 140 module consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 rtmodel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 module name, specifying . . . . . . . . . . . . . . . . . . . . . . . . . 141 MODULE (assembler directive) . . . . . . . . . . . . . . . . . . . . . 66 modules, assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 --module_name (compiler option) . . . . . . . . . . . . . . . . . . 141 _ _monitor (extended keyword) . . . . . . . . . . . . . . . . . . . . 154 using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 167 monitor functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21, 154 multibyte character support . . . . . . . . . . . . . . . . . . . . . . . . 136 multiple inheritance in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . . 85 mutable attribute, in Extended EC++ . . . . . . . . . . . . . . . . . 88
new (keyword) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 new (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 186 new.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 186 non-initialized variables . . . . . . . . . . . . . . . . . . . . . . . . . . 103 non-scalar parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 --no_code_motion (compiler option) . . . . . . . . . . . . . . . . 142 --no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 142 _ _no_init (extended keyword) . . . . . . . . . . . . . . . . . 103, 154 --no_inline (compiler option) . . . . . . . . . . . . . . . . . . 142143 (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 --no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 143 --no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 144 --no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 144 numeric (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . 187
O
-o (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 object filename, specifying . . . . . . . . . . . . . . . . . . . . . . . . 144 object module name, specifying . . . . . . . . . . . . . . . . . . . . 141 object_attribute (pragma directive) . . . . . . . . . . . . . . 103, 161 --omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 --only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 145 _ _open (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 operators @ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3536 optimization code motion, disabling . . . . . . . . . . . . . . . . . . . . . . . . . 142 common sub-expression elimination, disabling . . . . . . 142 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 function inlining, disabling . . . . . . . . . . . . . . . . . 142143 hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 loop unrolling, disabling . . . . . . . . . . . . . . . . . . . . . . . 143 size, specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 speed, specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 types and levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 optimization techniques code motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 common-subexpression elimination . . . . . . . . . . . . . . . . 93
N
namespace support in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . 86, 89 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . . 86 name, specifying for object file . . . . . . . . . . . . . . . . . . . . . 144 _ _nested (extended keyword). . . . . . . . . . . . . . . . . . . . . . 154 nested interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
221
function inlining. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 instruction scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . 96 loop unrolling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 static clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 type-based alias analysis . . . . . . . . . . . . . . . . . . . . . . . . 94 optimize (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . 162 options summary, compiler . . . . . . . . . . . . . . . . . . . . . . . . 127 ostream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 output specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 specifying file name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 output files, from XLINK . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 output, preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
P
pack (pragma directive) . . . . . . . . . . . . . . . . . . . . . . 114, 163 packed structure types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 parameters function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 hidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 non-scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7778 typographic convention . . . . . . . . . . . . . . . . . . . . . . . xviii permanent registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 placement of code and data . . . . . . . . . . . . . . . . . . . . . . . . 117 pointers casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 implementation-defined behavior . . . . . . . . . . . . . . . . . 193 using instead of large non-scalar parameters . . . . . . . . 100 polymorphism, in Embedded C++ . . . . . . . . . . . . . . . . . . . 85 _Pragma (preprocessor operator) . . . . . . . . . . . . . . . 173, 175 pragma directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 bitfields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110, 158 data_alignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
diag_default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 diag_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 diag_remark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 diag_suppress. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 diag_warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3536, 161 message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 object_attribute . . . . . . . . . . . . . . . . . . . . . . . . . . 103, 161 optimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 pack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114, 163 required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 rtmodel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 swi_number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 type_attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 _Pragma() (predefined symbol) . . . . . . . . . . . . . . . . . . . . 173 predefined symbols overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 _ _ALIGNOF_ _() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARMVFP_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARM4TM_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARM5E_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARM5TM_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARM5T_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _ARM5_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _BASE_FILE_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 _ _CORE_ _. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _cplusplus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _CPU_MODE_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _DATE_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _embedded_cplusplus . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _FILE_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 _ _FUNCTION_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
222
Reference Guide
Index
_ _func_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 _ _IAR_SYSTEMS_ICC_ _ . . . . . . . . . . . . . . . . . . . . 173 _ _ICCARM_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 _ _LINE_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 _ _LITTLE_ENDIAN_ _ . . . . . . . . . . . . . . . . . . . . . . . 173 _ _PRETTY_FUNCTION_ _ . . . . . . . . . . . . . . . . . . . 174 _ _STDC_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 _ _STDC_VERSION_ _ . . . . . . . . . . . . . . . . . . . . . . . 174 _ _TID_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 _ _TIME_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 _ _VER_ _ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 _Pragma() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 --preinclude (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 --preprocess (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 preprocessing directives, implementation-defined behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 preprocessor extension #warning message . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 __VA_ARGS__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 preprocessor output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 preprocessor symbols, defining . . . . . . . . . . . . . . . . . . . . . 131 preprocessor, extending. . . . . . . . . . . . . . . . . . . . . . . . . . . 140 prerequisites (programming experience) . . . . . . . . . . . . . . . xv _ _PRETTY_FUNCTION_ _ (predefined symbol) . . . . . . 174 print formatter, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 printf (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 printf (library function), choosing formatter . . . . . . . . . . . . 45 processor operations, low-level . . . . . . . . . . . . . . . . . . . . . 177 processor variant, specifying on command line. . . . . . . . . 130 programming experience, required . . . . . . . . . . . . . . . . . . . xv programming hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 ptrdiff_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 PUBLIC (assembler directive) . . . . . . . . . . . . . . . . . . . . . 146 --public_equ (compiler option) . . . . . . . . . . . . . . . . . . . . . 146
R
-r (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . 131, 146 raise (library function), configuring support for . . . . . . . . . 60 RAM execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 RAM memory, saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 _ _read (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 read formatter, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 reading guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv reading, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii realloc (standard library function) . . . . . . . . . . . . . . . . . . . . 13 recursive functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 storing data on stack . . . . . . . . . . . . . . . . . . . . . . . . 1213 reentrancy (DLIB). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 reference information, typographic convention . . . . . . . . xviii register parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii registers assigning to parameters . . . . . . . . . . . . . . . . . . . . . . . . . 77 callee-save, stored on stack . . . . . . . . . . . . . . . . . . . . . . 12 implementation-defined behavior . . . . . . . . . . . . . . . . . 193 permanent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 reinterpret_cast (cast operator) . . . . . . . . . . . . . . . . . . . . . . 86 remark (diagnostic message) classifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 enabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 --remarks (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 147 remarks (diagnostic message) . . . . . . . . . . . . . . . . . . . . . . 211 remove (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 rename (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 REQUIRE (assembler directive) . . . . . . . . . . . . . . . . . . . . . 66 required (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . 165 --require_prototypes (compiler option) . . . . . . . . . . . . . . . 147 return values, from functions . . . . . . . . . . . . . . . . . . . . . . . 79 _ _root (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . 155 routines, time-critical . . . . . . . . . . . . . . . . . . . . . . . . . 69, 177
Q
QCCARM (environment variable) . . . . . . . . . . . . . . . . . . 127 qualifiers, implementation-defined behavior . . . . . . . . . . . 194
223
RSEG (assembler directive) . . . . . . . . . . . . . . . . . . . . . . . . 66 RTMODEL (assembler directive) . . . . . . . . . . . . . . . . . . . . 64 rtmodel (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . 165 rtti support, missing from STL . . . . . . . . . . . . . . . . . . . . . . 86 _ _rt_version (runtime model attribute). . . . . . . . . . . . . . . . 65 runtime libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 runtime model attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 StackAlign4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 StackAlign8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 _ _cpu_mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 _ _endian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 _ _rt_version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 runtime type information, missing from Embedded C++ . . 85
S
-s (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 scanf (library function), choosing formatter . . . . . . . . . . . . 46 scatter loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 scratch registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 segment memory types, in XLINK . . . . . . . . . . . . . . . . . . . 26 segment parts, unused . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 segment (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . 166 segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 CODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 118 CODE_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 CODE_ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 CSTACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 DATA_AC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 DATA_AN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 DATA_ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 DATA_N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 DATA_Z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
DIFUNCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 HEAP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32, 120 ICODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 123 INITTAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 INTVEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34, 123 IRQ_STACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 SWITAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 _ _segment_begin (intrinsic function) . . . . . . . . . . . . . . . . 180 _ _segment_end (intrinsic function) . . . . . . . . . . . . . . . . . 180 semaphores, operations on . . . . . . . . . . . . . . . . . . . . . . . . 154 set (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 setjmp.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 settings, basic for project configuration . . . . . . . . . . . . . . . . 5 severity level, of diagnostic messages . . . . . . . . . . . . . . . . 211 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 _ _sfb (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _sfe (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 180 SFR (special function registers) . . . . . . . . . . . . . . . . . . . . 102 declaring extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 short (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 signal (library function), configuring support for . . . . . . . . 60 signal.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 signed char (data type) . . . . . . . . . . . . . . . . . . . . . . . 108109 specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 signed int (data type). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 signed long (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 signed short (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 --silent (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 148 silent operation, specifying . . . . . . . . . . . . . . . . . . . . . . . . 148 64-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 110 size optimization, specifying. . . . . . . . . . . . . . . . . . . . . . . 149 size_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 skeleton code, creating for assembler language interface . . 72 slist (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 software interrupt handler . . . . . . . . . . . . . . . . . . . . . . . . . . 19 software interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 source files, list all referred . . . . . . . . . . . . . . . . . . . . . . . . 137
224
Reference Guide
Index
special function registers (SFR) . . . . . . . . . . . . . . . . . . . . 102 special function types overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 speed optimization, specifying . . . . . . . . . . . . . . . . . . . . . 147 sprintf (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 sprintf (library function), choosing formatter . . . . . . . . . . . 45 sscanf (library function), choosing formatter . . . . . . . . . . . 46 sstream (library header file) . . . . . . . . . . . . . . . . . . . . . . . 186 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 advantages and problems using . . . . . . . . . . . . . . . . . . . 12 contents of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 function usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 internal data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 saving space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 stack alignment specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 stack parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7778 stack pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 stack (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 StackAlign4 (runtime model attribute) . . . . . . . . . . . . . . . . 65 StackAlign8 (runtime model attribute) . . . . . . . . . . . . . . . . 65 standard error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 standard output, specifying . . . . . . . . . . . . . . . . . . . . . . . . 145 standard template library (STL) in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . 86, 88, 186 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . . 86 startup code placement of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 See also ICODE startup, system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 statements, implementation-defined behavior . . . . . . . . . . 194 Static clustering (compiler option) . . . . . . . . . . . . . . . . . . . 96 static memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 static overlay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 static_cast (cast operator) . . . . . . . . . . . . . . . . . . . . . . . . . . 86 std namespace, missing from EC++ and Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 stdarg.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185
stdbool.h (library header file) . . . . . . . . . . . . . . . . . . 109, 185 _ _STDC_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 174 _ _STDC_VERSION_ _ (predefined symbol) . . . . . . . . . 174 stddef.h (library header file) . . . . . . . . . . . . . . . . . . . 109, 185 stderr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57, 145 stdexcept (library header file) . . . . . . . . . . . . . . . . . . . . . . 186 stdin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 stdio.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185 stdlib.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185 stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57, 145 STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 streambuf (library header file). . . . . . . . . . . . . . . . . . . . . . 186 streams, supported in Embedded C++. . . . . . . . . . . . . . . . . 86 --strict_ansi (compiler option). . . . . . . . . . . . . . . . . . . . . . 149 string (library header file) . . . . . . . . . . . . . . . . . . . . . . . . . 186 strings, supported in Embedded C++ . . . . . . . . . . . . . . . . . 86 string.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 strstream (library header file) . . . . . . . . . . . . . . . . . . . . . . 186 strtod (library function), configuring support for . . . . . . . . 61 structure types alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113114 layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 packed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 structures anonymous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 implementation-defined behavior . . . . . . . . . . . . . . . . . 193 Support, Technical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 SWITAB (segment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 swi_number (pragma directive) . . . . . . . . . . . . . . . . . . . . 166 symbols anonymous, creating . . . . . . . . . . . . . . . . . . . . . . . . . . 203 predefined, overview of . . . . . . . . . . . . . . . . . . . . . . . . . 10 preprocessor, defining . . . . . . . . . . . . . . . . . . . . . . . . . 131 system startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 system termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 system (library function), configuring support for . . . . . . . 59
225
T
Technical Support, IAR . . . . . . . . . . . . . . . . . . . . . . . . . . 212 template support in Extended EC++ . . . . . . . . . . . . . . . . . . . . . . . . . . 86, 88 missing from Embedded C++ . . . . . . . . . . . . . . . . . . . . 85 termination, system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv, xviii 32-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 110 this (pointer) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Thumb (CPU mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 _ _TID_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 174 _ _TIME_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 175 time (library function), configuring support for . . . . . . . . . 61 time-critical routines . . . . . . . . . . . . . . . . . . . . . . . . . . 69, 177 time.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . . 185 tips, programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii translation, implementation-defined behavior . . . . . . . . . . 189 trap vectors, specifying with pragma directive . . . . . . . . . 167 type information, omitting . . . . . . . . . . . . . . . . . . . . . . . . 145 Type-based alias analysis (compiler option) . . . . . . . . . . . . 94 type-safe memory management . . . . . . . . . . . . . . . . . . . . . 85 type_attribute (pragma directive) . . . . . . . . . . . . . . . . . . . 166 typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . xviii
V
variable type information omitting in object output . . . . . . . . . . . . . . . . . . . . . . . 145 variables auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1112, 100 defined inside a function . . . . . . . . . . . . . . . . . . . . . . . . 11 global placement in memory . . . . . . . . . . . . . . . . . . . . . . . . 11 local. See auto variables non-initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 omitting type info . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 placing at absolute addresses . . . . . . . . . . . . . . . . . . . . . 35 placing in named segments . . . . . . . . . . . . . . . . . . . . . . 35 placing in segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 static, placement in memory . . . . . . . . . . . . . . . . . . . . . 11 vector floating-point unit . . . . . . . . . . . . . . . . . . . . . . . . . 137 vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 vector (pragma directive) . . . . . . . . . . . . . . . . . . . . . . . . . 167 vector (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 187 _ _VER_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 175 version, of compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 VFP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 volatile, declaring objects . . . . . . . . . . . . . . . . . . . . . . . . . 115
U
uintptr_t (integer type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 unions anonymous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 implementation-defined behavior . . . . . . . . . . . . . . . . . 193 unsigned char (data type) . . . . . . . . . . . . . . . . . . . . . 108109 changing to signed char . . . . . . . . . . . . . . . . . . . . . . . . 130 unsigned int (data type) . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 unsigned short (data type) . . . . . . . . . . . . . . . . . . . . . 108109 utility (STL header file) . . . . . . . . . . . . . . . . . . . . . . . . . . 187
W
#warning message (preprocessor extension) . . . . . . . . . . . 175 warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 classifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 disabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 exit code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 --warnings_affect_exit_code (compiler option) . . . . . . . . 127 --warnings_are_errors (compiler option) . . . . . . . . . . . . . 149 wchar.h (library header file) . . . . . . . . . . . . . . . . . . . . . . . 185 wchar_t (data type) adding support for in C . . . . . . . . . . . . . . . . . . . . . . . . 109 wctype.h (library header file) . . . . . . . . . . . . . . . . . . . . . . 185 _ _write (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57
226
Reference Guide
Index
X
XLINK options -Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 XLINK output files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 XLINK segment memory types . . . . . . . . . . . . . . . . . . . . . 26
Z
-z (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Symbols
#include files, specifying . . . . . . . . . . . . . . . . . . . . . . . . . 138 #pragma directives location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 #warning message (preprocessor extension) . . . . . . . . . . . 175 -D (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 -e (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 -f (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 -I (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 -l (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 73, 139 -o (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 -Q (XLINK option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 -r (compiler option). . . . . . . . . . . . . . . . . . . . . . . . . . 131, 146 -s (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 -z (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 --char_is_signed (compiler option) . . . . . . . . . . . . . . . . . . 130 --cpu (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 --cpu_mode (compiler option) . . . . . . . . . . . . . . . . . . . . . 130 --debug (compiler option) . . . . . . . . . . . . . . . . . . . . . 131, 146 --dependencies (compiler option) . . . . . . . . . . . . . . . . . . . 132 --diagnostics_tables (compiler option) . . . . . . . . . . . . . . . 134 --diag_error (compiler option) . . . . . . . . . . . . . . . . . . . . . 133 --diag_remark (compiler option) . . . . . . . . . . . . . . . . . . . . 133 --diag_suppress (compiler option) . . . . . . . . . . . . . . . . . . 134 --diag_warning (compiler option) . . . . . . . . . . . . . . . . . . . 134 --dlib_config (compiler option) . . . . . . . . . . . . . . . . . . . . . 135 --ec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . 135
--eec++ (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 136 --enable_multibytes (compiler option) . . . . . . . . . . . . . . . 136 --endian (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 136 --fpu (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 --header_context (compiler option) . . . . . . . . . . . . . . . . . . 137 --interwork (compiler option) . . . . . . . . . . . . . . . . . . . . . . 139 --library_module (compiler option) . . . . . . . . . . . . . . . . . 140 --migration_preprocessor_extensions (compiler option) . . 140 --module_name (compiler option) . . . . . . . . . . . . . . . . . . 141 --no_clustering (compiler option) . . . . . . . . . . . . . . . . . . . 141 --no_code_motion (compiler option) . . . . . . . . . . . . . . . . 142 --no_cse (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . 142 --no_inline (compiler option) . . . . . . . . . . . . . . . . . . 142143 --no_scheduling (compiler option) . . . . . . . . . . . . . . . . . . 143 --no_tbaa (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 143 --no_typedefs_in_diagnostics (compiler option) . . . . . . . . 143 --no_unroll (compiler option) . . . . . . . . . . . . . . . . . . . . . . 143 --no_warnings (compiler option) . . . . . . . . . . . . . . . . . . . 144 --no_wrap_diagnostics (compiler option) . . . . . . . . . . . . . 144 --omit_types (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 --only_stdout (compiler option) . . . . . . . . . . . . . . . . . . . . 145 --preinclude (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 --preprocess (compiler option) . . . . . . . . . . . . . . . . . . . . . 145 --remarks (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 147 --require_prototypes (compiler option) . . . . . . . . . . . . . . . 147 --segment (compiler option) . . . . . . . . . . . . . . . . . . . . . . . 148 --separate_cluster_for_initialized_variables (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 --silent (compiler option) . . . . . . . . . . . . . . . . . . . . . . . . . 148 --stack_align (compiler option) . . . . . . . . . . . . . . . . . . . . . 148 --strict_ansi (compiler option). . . . . . . . . . . . . . . . . . . . . . 149 --warnings_affect_exit_code (compiler option) . . . . 127, 149 --warnings_are_errors (compiler option) . . . . . . . . . . . . . 149 @ (operator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3536 _ _ALIGNOF_ _() (predefined symbol) . . . . . . . . . . . . . . 171 _ _arm (extended keyword). . . . . . . . . . . . . . . . . . . . . . . . 152 _ _ARMVFP_ _ (predefined symbol) . . . . . . . . . . . . . . . . 171 _ _ARM4TM_ _ (predefined symbol) . . . . . . . . . . . . . . . 171 _ _ARM5E_ _ (predefined symbol) . . . . . . . . . . . . . . . . . 171
227
_ _ARM5TM_ _ (predefined symbol) . . . . . . . . . . . . . . . 171 _ _ARM5T_ _ (predefined symbol) . . . . . . . . . . . . . . . . . 171 _ _ARM5_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . 171 _ _BASE_FILE_ _ (predefined symbol) . . . . . . . . . . . . . . 171 _ _close (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _CLZ (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . 178 _ _CORE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 172 _ _cplusplus (predefined symbol) . . . . . . . . . . . . . . . . . . . 172 _ _cpu_mode (runtime model attribute) . . . . . . . . . . . . . . . 65 _ _CPU_MODE_ _ (predefined symbol) . . . . . . . . . . . . . 172 _ _DATE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 172 _ _disable_interrupt (intrinsic function) . . . . . . . . . . . . . . 178 _ _embedded_cplusplus (predefined symbol) . . . . . . . . . . 172 _ _enable_interrupt (intrinsic function) . . . . . . . . . . . . . . . 178 _ _endian (runtime model attribute) . . . . . . . . . . . . . . . . . . 65 _ _FILE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 172 _ _fiq (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 153 _ _FUNCTION_ _ (predefined symbol) . . . . . . . . . . . . . . 173 _ _func_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 173 _ _get_CPSR (intrinsic function) . . . . . . . . . . . . . . . . . . . 178 _ _IAR_SYSTEMS_ICC_ _ (predefined symbol) . . . . . . 173 _ _ICCARM_ _ (predefined symbol) . . . . . . . . . . . . . . . . 173 _ _interwork (extended keyword) . . . . . . . . . . . . . . . . . . . 153 _ _intrinsic (extended keyword) . . . . . . . . . . . . . . . . . . . . 153 _ _irq (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 153 using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 167 _ _LINE_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 173 _ _LITTLE_ENDIAN_ _ (predefined symbol) . . . . . . . . . 173 _ _low_level_init, customizing . . . . . . . . . . . . . . . . . . . . . . 53 _ _lseek (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _MCR (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . 178 _ _monitor (extended keyword) . . . . . . . . . . . . . . . . . . . . 154 using in pragma directives . . . . . . . . . . . . . . . . . . . . . . 167 _ _MRC (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . 179 _ _nested (extended keyword). . . . . . . . . . . . . . . . . . . . . . 154 _ _no_init (extended keyword) . . . . . . . . . . . . . . . . . 103, 154 _ _no_operation (intrinsic function) . . . . . . . . . . . . . . . . . 179 _ _open (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _PRETTY_FUNCTION_ _ (predefined symbol) . . . . . . 174
_ _QADD (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . 180 _ _QDADD (intrinsic function) . . . . . . . . . . . . . . . . . . . . 180 _ _QDSUB (intrinsic function) . . . . . . . . . . . . . . . . . . . . . 181 _ _QSUB (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . 181 _ _ramfunc (extended keyword) . . . . . . . . . . . . . 16, 154155 _ _read (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _ _root (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . 155 _ _rt_version (runtime model attribute). . . . . . . . . . . . . . . . 65 _ _segment_begin (intrinsic function) . . . . . . . . . . . . . . . . 180 _ _segment_end (intrinsic function) . . . . . . . . . . . . . . . . . 180 _ _segment_size (intrinsic function) . . . . . . . . . . . . . . . . . 180 _ _set_CPSR (intrinsic function) . . . . . . . . . . . . . . . . . . . 179 _ _sfb (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _sfe (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _sfs (intrinsic function) . . . . . . . . . . . . . . . . . . . . . . . . . 180 _ _STDC_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 174 _ _STDC_VERSION_ _ (predefined symbol) . . . . . . . . . 174 _ _swi (extended keyword) . . . . . . . . . . . . . . . . . . . . . . . . 155 _ _thumb (extended keyword) . . . . . . . . . . . . . . . . . . . . . . 156 _ _TID_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . . 174 _ _TIME_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . 175 _ _VER_ _ (predefined symbol) . . . . . . . . . . . . . . . . . . . . 175 _ _write (library function) . . . . . . . . . . . . . . . . . . . . . . . . . . 57 _formatted_write (library function) . . . . . . . . . . . . . . . . . . 45 _Pragma (preprocessor operator) . . . . . . . . . . . . . . . 173, 175 _Pragma() (predefined symbol) . . . . . . . . . . . . . . . . . . . . 173 __VA_ARGS__ (preprocessor extension) . . . . . . . . . . . . . 176
Numerics
32-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 110 64-bits (floating-point format) . . . . . . . . . . . . . . . . . . . . . 110
228
Reference Guide