EWMISRAC:2004-1
IAR Embedded Workbench®
MISRA C:2004
Reference Guide
EWMISRAC:2004-1
COPYRIGHT NOTICE
© Copyright 2004–2008 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 Systems, IAR Embedded Workbench, C-SPY, visualSTATE, From Idea To Target,
IAR KickStart Kit, IAR PowerPac, IAR YellowSuite, IAR Advanced Development Kit,
IAR, and the IAR Systems logotype are trademarks or registered trademarks owned by
IAR Systems AB. J-Link is a trademark licensed to IAR Systems AB.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
All other product names are trademarks or registered trademarks of their respective
owners.
EDITION NOTICE
Third edition: March 2008
Part number: EWMISRAC:2004-1
This guide describes version 1.0 of the IAR Systems implementation of The Motor
Industry Software Reliability Association’s Guidelines for the Use of the C Language
in Critical Systems (the MISRA-C:2004 standard), including the MISRA-C:2004
Technical Corrigendum 1, dated 17 July, 2007.
Internal reference: IJOA
EWMISRAC:2004-1
iii
Contents
Preface ...................................................................................................................... 1
Who should read this guide ................................................................. 1
What this guide contains ....................................................................... 1
Other documentation ............................................................................. 2
Document conventions .......................................................................... 2
Introduction .......................................................................................................... 5
Using MISRA C .......................................................................................... 5
Claiming compliance ........................................................................... 5
Implementation and interpretation of the MISRA C rules .... 5
Checking the rules ................................................................................ 6
Enabling MISRA C rules ......................................................................... 7
General IDE options ......................................................................................... 9
MISRA C 2004 ........................................................................................... 9
Compiler IDE options .................................................................................... 11
MISRA C 2004 ......................................................................................... 11
Command line options .................................................................................. 13
Options summary ................................................................................... 13
Descriptions of options ........................................................................ 13
MISRA C:2004 rules reference .................................................................. 15
Summary of rules .................................................................................. 15
Group 1: Environment ....................................................................... 15
Group 2: Language extensions ........................................................... 16
Group 3: Documentation .................................................................... 16
Group 4: Character sets ...................................................................... 16
Group 5: Identifiers ............................................................................ 17
Group 6: Types ................................................................................... 17
Group 7: Constants ............................................................................. 17
Group 8: Declarations and definitions ............................................... 18
EWMISRAC:2004-1
iv
IAR Embedded Workbench® MISRA C:2004
Reference Guide
Group 9: Initialization ........................................................................ 19
Group 10: Arithmetic type conversions ............................................. 19
Group 11: Pointer type conversions ................................................... 20
Group 12: Expressions ....................................................................... 20
Group 13: Control statement expressions .......................................... 21
Group 14: Control flow ...................................................................... 22
Group 15: Switch statements ............................................................. 23
Group 16: Functions ........................................................................... 23
Group 17: Pointers and arrays ............................................................ 24
Group 18: Structures and unions ........................................................ 24
Group 19: Preprocessing directives ................................................... 25
Group 20: Standard libraries .............................................................. 26
Group 21: Runtime failures ................................................................ 27
Environment rules .................................................................................. 27
Language extensions ............................................................................. 28
Documentation ........................................................................................ 29
Character sets .......................................................................................... 31
Identifiers ................................................................................................... 32
Types ............................................................................................................ 33
Constants ................................................................................................... 35
Declarations and definitions .............................................................. 35
Initialization .............................................................................................. 38
Arithmetic type conversions ............................................................. 39
Pointer type conversions ..................................................................... 42
Expressions ................................................................................................ 43
Control statement expressions ........................................................ 47
Control flow .............................................................................................. 49
Switch statements .................................................................................. 52
Functions .................................................................................................... 53
Pointers and arrays ................................................................................ 56
Structures and unions ........................................................................... 57
Preprocessing directives ...................................................................... 58
Standard libraries ................................................................................... 63
Runtime failures ...................................................................................... 65
EWMISRAC:2004-1
1
Preface
Welcome to the IAR Embedded Workbench® MISRA C:2004 Reference
Guide. This guide includes gives reference information about the IAR Systems
implementation of The Motor Industry Software Reliability Association’s
Guidelines for the Use of the C Language in Critical Systems.
Who should read this guide
You should read this guide if you are developing a software product using the
MISRA-C:2004 rules. In addition, you should have a working knowledge of:
● The C programming language
● The MISRA C subset of the C language
● Application development for safety-critical embedded systems
● The architecture and instruction set of your microcontroller (refer to the chip
manufacturer's documentation)
● The operating system of your host machine.
What this guide contains
Below is a brief outline and summary of the chapters in this guide.
● Introduction explains the benefits of using MISRA C and gives an overview of the
IAR Systems implementation.
● General IDE options describes the general MISRA C options in the IAR Embedded
Workbench IDE.
● Compiler IDE options describes the MISRA C compiler options in the IAR
Embedded Workbench IDE.
● Command line options explains how to set the options from the command line.
● MISRA C:2004 rules reference describes how IAR Systems has interpreted and
implemented the rules given in Guidelines for the Use of the C Language in Critical
Systems, including the MISRA-C:2004 Technical Corrigendum 1, dated 17 July,
2007.