Codewarrior® C Compilers Reference
Total Page:16
File Type:pdf, Size:1020Kb
CodeWarrior® C Compilers Reference Because of last-minute changes to CodeWarrior, some of the information in this manual may be inaccurate. Please read the Release Notes on the CodeWarrior CD for the latest up-to-date information. Revised: 99/12/06 map Metrowerks CodeWarrior copyright ©1993–2000 by Metrowerks, Inc. and its licensors. All rights reserved. Documentation stored on the compact disk(s) may be printed by licensee for personal use. Except for the foregoing, no part of this documentation may be reproduced or transmitted in any form by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from Metrowerks, Inc. Metrowerks, the Metrowerks logo, CodeWarrior, PowerPlant, and Metrowerks University are registered trademarks of Metrowerks Inc. CodeWarrior Constructor, Geekware, PowerParts, and Discover Programming are trademarks of Metrowerks Inc. All other trademarks and registered trademarks are the property of their respective owners. ALL SOFTWARE AND DOCUMENTATION ON THE COMPACT DISK(S) ARE SUBJECT TO THE LICENSE AGREEMENT IN THE CD BOOKLET. How to Contact Metrowerks: U.S.A. and international Metrowerks Corporation 9801 Metric, Suite #100 Austin, TX 78758 U.S.A. Canada Metrowerks Inc. 1500 du College, Suite 300 Ville St-Laurent, QC Canada H4L 5G6 Ordering Voice: (800) 377–5416 Fax: (512) 873–4901 World Wide Web http://www.metrowerks.com Registration information [email protected] Desktop/Games Technical support [email protected] Embedded Technical support [email protected] Sales, marketing, & licensing [email protected] International Ordering Voice: +1 512 873 4724 Fax: +1 512 873 4901 Intl. Sales, marketing, & licensing [email protected] Table of Contents 1 Introduction 11 What’s in this Reference? . 11 Read the Release Notes! . 12 What’s New . 12 CodeWarrior Year 2000 Compliance . 13 Conventions Used in This Reference . 13 2 Setting C/C++ Compiler Options 15 Setting C Compiler Options Overview. 15 C/C++ Language Panel . 15 C/C++ Warnings Panel . 18 Treat All Warnings as Errors . 20 Illegal Pragmas . 20 Empty Declarations. 20 Possible Errors . 21 Unused Variables. 22 Unused Arguments. 23 Extra Commas . 24 Extended Error Checking . 24 Hidden Virtual Functions . 25 Implicit Arithmetic Conversions . 26 Non-Inlined Functions . 26 Inconsistent Use of ‘class’ and ‘struct’ Keywords . 26 3 C Compiler 29 C Compiler Overview . 29 Identifiers . 30 Include Files . 30 Prefix Files . 32 Sizeof() Operator . 32 Volatile Variables. 32 Enumerated Types . 33 Extensions to ANSI/ISO C . 35 ANSI Strict . 36 Using the wchar_t Type . 37 C Compilers Reference CCR–3 C++ Style Comments . 37 Unnamed Arguments in Function Definitions . 38 A # not Followed by Argument in a Macro . 38 Using an Identifier After #endif . 38 Using Typecasted Pointers as lvalues . 39 Declaring Variables By Address . 40 ANSI Keywords Only. 40 Expand Trigraphs . 41 Character Constants as Integer Values. 42 Inlining . 42 Multibyte Strings and Comments. 44 Pool Strings . 44 Reusing Strings . 45 Require Function Prototypes . 46 Map Newlines to CR . 48 Relaxed Pointer Type Rules . 49 Use Unsigned Chars . 50 Using 64-bit Integers . 50 Converting Pointers to Types of the Same Size . 51 Getting Alignment and Type Information at Compile-Time . 51 Arrays of Zero Length in Structures. 51 Intrinsic Functions for Bit Rotation . 52 The “D” Constant Suffix. 52 The short double Data Type . 53 GNU C Extensions . 53 4 C++ Compiler 55 C++ Compiler Overview . 55 CodeWarrior Implementation of C++ . 56 Implicit Return Statement for main() . 57 Keyword Ordering . 57 Additional Keywords . 58 Conversions in the Conditional Operator . 58 Default Arguments in Member Functions . 58 Local Class Declarations with Inline Functions . 59 Copying and Constructing Class Objects . 59 Checking for Resources To Initialize Static Data . 60 CCR–4 C Compilers Reference Calling an Inherited Member Function . 61 Unsupported Extensions. 63 Controlling the C++ Compiler . 63 Using the C++ Compiler Always . 64 Controlling ARM Conformance . 64 Controlling Exception Handling . 65 Controlling RTTI . 66 Using the bool Type . 66 Controlling C++ Extensions . 67 Working With C++ Exceptions . 68 Working With RTTI . 68 Using the dynamic_cast Operator . 68 Using the typeid Operator . 70 Working With Templates. 71 Declaring and Defining Templates . 72 Instantiating a Template. 75 5 C++ and Embedded Systems 79 C++ and Embedded Systems Overview . 79 Activating EC++ . 79 Differences Between ANSI/ISO C++ and EC++ . 80 Templates . 80 Libraries . 80 File Operations. 80 Localization . 80 Exception Handling . 81 Other Language Features . 81 Meeting EC++ Specifications With CodeWarrior . 81 Language Related Issues . 81 Library Related Issues . 82 Strategies for Smaller Code Size in C++ . 82 Size Optimizations . 83 Inlining . 83 Virtual Functions. 84 Runtime Type Identification . 84 Exception Handling . 84 Operator New . 85 C Compilers Reference CCR–5 Multiple Inheritance . 85 Virtual Inheritance . 85 Stream-Based Classes . 86 Alternative Class Libraries. 86 6 Pragmas and Symbols 87 Pragmas and Symbols Overview . 87 Pragmas . 88 Pragma Syntax. 88 Pragma Scope . 88 a6frames . 90 align . 90 align_array_members . 92 altivec_codegen . 93 altivec_model . 93 altivec_vrsave . 94 always_inline . 94 ANSI_strict . 94 arg_dep_lookup . 95 ARM_conform . 96 auto_inline . 97 bool . 97 check_header_flags . 98 code_seg . 99 code68020 . 99 code68881 . 100 cplusplus . 101 cpp_extensions. 101 d0_pointers . 102 data_seg . 103 def_inherited . 104 defer_codegen . 104 define_section . 105 direct_destruction . 109 direct_to_som . 109 disable_registers . 110 dollar_identifiers . 111 CCR–6 C Compilers Reference dont_inline . 111 dont_reuse_strings . 112 ecplusplus. 113 EIPC_EIPSW . 113 enumsalwaysint . 114 exceptions. 115 export . 115 extended_errorcheck . 117 far_code, near_code, smart_code . 119 far_data . 119 far_strings. 120 far_vtables . 120 faster_pch_gen. 121 float_constants . 121 force_active . 122 fourbyteints . 122 fp_contract . 123 fp_pilot_traps . 124 fullpath_prepdump. 124 function. 124 gcc_extensions . 125.