View
237
Download
3
Embed Size (px)
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
1/323
AVR IAR C/C++ CompilerReference Guide
for Atmel Corporations
AVRMicrocontroller
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
2/323
COPYRIGHT NOTICE Copyright 19962005 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.
DISCLAIMERThe 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 containedherein 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.
TRADEMARKSIAR Systems, From Idea to Target, IAR Embedded Workbench, visualSTATE, IAR
MakeApp and C-SPY are trademarks owned by IAR Systems AB.
Atmel is a registered trademark of Atmel Corporation. AVR is a registered trademark of
Atmel Corporation.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
All other product names are trademarks or registered trademarks of their respective
owners.
EDITION NOTICE
Fourth edition: February 2005
Part number: CAVR-4
This guide applies to version 4.x of AVR IAR Embedded Workbench.
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
3/323
iii
Brief contentsTables ...................................................................................................................... xv
Preface ................................................................................................................... xix
Part 1. Using the compiler......................................................... 1
Getting started .................................................................................................... 3
Data storage ...................................................................................................... 15
Functions ............................................................................................................. 27
Placing code and data .................................................................................... 33
The DLIB runtime environment ............................................................... 53
The CLIB runtime environment .............................................................. 85
Assembler language interface ................................................................... 93
Using C++ .......................................................................................................... 109
Efficient coding for embedded applications ...................................... 121
Part 2. Compiler reference ....................................................135
Data representation ...................................................................................... 137
Segment reference ......................................................................................... 149
Compiler options ........................................................................................... 167
Extended keywords ....................................................................................... 203
Pragma directives ............................................................................................ 215
The preprocessor ........................................................................................... 227
Intrinsic functions ........................................................................................... 237
Library functions ............................................................................................. 243
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
4/323iv
AVR IAR C/C++ Compiler
Reference Guide
Implementation-defined behavior .......................................................... 255
IAR language extensions ............................................................................. 269
Diagnostics ......................................................................................................... 279
Index ..................................................................................................................... 281
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
5/323
v
ContentsTables ...................................................................................................................... xv
Preface ................................................................................................................... xix
Who should read this guide ..............................................................xix
How to use this guide .........................................................................xixWhat this guide contains ..................................................................... xx
Other documentation..........................................................................xxi
Further reading ..................................................................................xxi
Document conventions ......................................................................xxii
Typographic conventions .................................................................xxii
Part 1. Using the compiler ......................................................... 1
Getting started .................................................................................................... 3
IAR language overview ...........................................................................3
Building applicationsan overview ..................................................4
Compiling ............................................................................................. 4
Linking ................................................................................................. 4
Basic settings for project configuration ..........................................5
Processor configuration ........................................................................ 5
Memory model .....................................................................................9
Size of double floating-point type ......................................................10
Optimization for speed and size .........................................................10
Runtime environment ......................................................................... 11
Special support for embedded systems ........................................ 12
Extended keywords ............................................................................ 12
Pragma directives ...............................................................................13
Predefined symbols ............................................................................13
Header files for I/O ............................................................................13
Accessing low-level features .............................................................13
7/28/2019 AVR IAR C/C++ Compiler Reference Guide
6/323
vi
AVR IAR C/C++ Compiler
Reference Guide
Data storage ...................................................................................................... 15
Introduction .............................................................................................. 15
Storing data ........................................................................................15
Extended keywords for data ...............................................................16
Memory models ......................................................................................17
Specifying a memory model ..............................................................17
Memory types and memory attributes ......................................... 18Using data memory attributes ............................................................19
Pointers and memory types ................................................................ 20
Structures and memory types ............................................................21
More examples ...................................................................................21
C++ and memory types ...................................................................... 22
The stack and auto variables ............................................................. 23
Dynamic memory on the heap ........................................................25
Functions ............................................................................................................. 27
Controlling functions ............................................................................27
Extended keywords for functions ......................................................27
Function storage .....................................................................................28
Special function types ..........................................................................29
Interrupt functions ...............................