Codewarrior C, C++, and Assembly Language Reference
Total Page:16
File Type:pdf, Size:1020Kb
CodeWarrior® C, C++, and Assembly Language 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. Metrowerks CodeWarrior copyright ©1993–1996 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 trans- mitted 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, and Software at Work are registered trademarks of Metrowerks Inc. PowerPlant and PowerPlant Constructor 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 2201 Donley Drive, Suite 310 Austin, TX 78758 U.S.A. Canada Metrowerks Inc. 1500 du College, Suite 300 Ville St-Laurent, QC Canada H4L 5G6 Mail order Voice: (800) 377–5416 Fax: (512) 873–4901 World Wide Web http://www.metrowerks.com Registration information [email protected] Technical support [email protected] Sales, marketing, & licensing [email protected] America Online keyword: Metrowerks CompuServe goto Metrowerks Table of Contents 1 Introduction . 13 Overview of the C/C++/ASM Reference . 13 Conventions Used in This Manual . 14 The C/C++ Project Settings Panels . 14 What’s New . 17 The long long type . 17 Turning off register coloring in the 68K compiler . 17 More information on enumerated types . 17 New pragmas . 17 New intrinsic functions . 18 Improved documentation . 18 2 C and C++ Language Notes . 19 Overview of C and C++ Language Notes . 19 The Metrowerks Implementation of C and C++ . 20 Identifiers . 21 Include files . 21 The sizeof() operator . 22 Register variables . 23 Register coloring. 24 Volatile variables . 25 Limits on variable sizes . 26 Declaration specifiers . 27 Enumerated types . 28 Number Formats . 30 68K Macintosh integer formats . 30 68K Macintosh floating-point formats . 32 PowerPC Macintosh, Magic Cap, and Win32/x86 integer formats 33 PowerPC Macintosh and Win32/x86 floating-point formats . 34 Magic Cap Floating-Point Formats . 34 Calling Conventions . 35 68K Macintosh calling conventions . 35 PowerPC calling conventions . 36 C, C++, and Assembly Language Reference CL–3 Magic Cap calling conventions . 39 Win32/x86 calling conventions. 39 Extensions to C or C++ . 40 ANSI extensions you can’t disable . 42 Multibyte characters (Macintosh Only) . 43 Declaring variables by address (Macintosh Only) . 43 Opcode inline functions (68K Macintosh Only) . 43 Inline data (68K Macintosh Only) . 44 Specifying the registers for arguments (68K Macintosh Only) 45 64-bit integers . 46 ANSI extensions you disable with ANSI Strict . 47 C++-style comments . 48 Unnamed arguments in function definitions . 48 A # not followed by argument in macro definition . 48 An identifier after #endif . 48 Using typecasted pointers as lvalues . 49 Disabling trigraph characters . 49 Additional keywords . 50 Macintosh and Magic Cap keywords . 50 Win32/x86 keywords. 51 Enumerated constants of any size . 51 Chars always unsigned . 52 Inlining functions . 52 Using multibyte strings and comments . 53 Using prototypes . 54 Requiring prototypes . 54 Relaxing pointer checking. 56 Storing strings (Macintosh only) . 56 Pooling strings . 56 Using PC-relative strings . 57 Reusing strings . 58 Warnings for Common Mistakes . 59 Treat warnings as errors . 60 Illegal pragmas . 60 Empty declarations . 61 CL–4 C, C++, and Assembly Language Reference Possible unwanted side effects . 61 Unused variables. 62 Unused arguments . 63 Extra commas . 64 Extended type checking . 65 Function hiding . 66 Generating Code for Specific 68K Processors (Macintosh Only) . 67 Generating code for the MC68020 . 70 Generating code for the MC68881 . 70 Using the Extended data type . 71 Using floating-point registers . 72 Calling MPW Functions . 72 Adding an MPW library to a CodeWarrior project . 73 Declaring MPW C functions (Macintosh Only) . 75 Using MPW C newlines . 76 Calling Macintosh Toolbox Functions (Macintosh Only) . 77 Passing string arguments . 78 Using the pascal keyword in PowerPC code . 79 Intrinsic PowerPC Functions (Macintosh Only) . 80 Low-level processor synchronization . 80 Floating-point functions. 81 Byte-reversing functions . 81 Setting the floating-point environment . 82 Floating-point instructions for the 603 and 604 . 82 Rotating the contents of a variable . 83 3 C++ Language Notes . 85 Overview of C++ Language Notes . 85 Unsupported Extensions. 86 Metrowerks Implementation of C++ . 86 Which keywords to put first . 87 Additional keywords . 87 Conversions in the conditional operator . 87 Default arguments in member functions. 88 Local class declarations with inline functions. 89 Copying and constructing class objects . 89 C, C++, and Assembly Language Reference CL–5 Checking for resources to initialize static data . 90 Calling an inherited member function. 91 Setting C++ Options . 92 Using the C++ compiler always . 93 Enforcing strict ARM conformance . 94 Adding C++ extensions. 95 Allowing exception handling . 96 Using the bool type . 96 Using Run-Time Type Information (RTTI) . 96 Using the dynamic_cast operator . 97 Using the typeid operator . 98 Using Templates . 99 Declaring and defining templates. 100 Instantiating templates . 101 Using Exceptions . 103 Declaring MPW-Compatible Classes . 104 Creating Direct-to-SOM Code . 105 SOM class restrictions. 106 Using SOM headers . 109 Automatic SOM error checking . 109 Using SOM pragmas . 111 Declaring the release order . 112 Declaring the class’s version. 112 Declaring the metaclass for a class . 113 Declaring the call style for a class . 113 4 68K Assembler Notes . 115 Overview of 68K Assembler Notes . 115 Writing an Assembly Function for 68K. 116 Defining a Function for 68K Assembly . 116 Using Global Variables in 68K Assembly . 119 Using Local Variables and Arguments in 68K Assembly . 119 Using Structures in 68K Assembly . 120 Using the Preprocessor in 68K Assembly . 121 Returning From a Function in 68K Assembly. 121 Assembler directives . 122 CL–6 C, C++, and Assembly Language Reference dc . 122 ds . 122 entry . 123 fralloc . 123 frfree . 123 machine . 124 opword. 124 5 PowerPC Assembler Notes. 125 Overview of PowerPC Assembler Notes . 125 Writing an Assembly Function for PowerPC . 126 Defining a Function for PowerPC Assembly . 126 Creating Labels for PowerPC Assembly . 128 Using Comments for Power PCAssembly . 129 Using the Preprocessor for PowerPC Assembly. 129 Creating a Stack Frame for PowerPC Assembly. 129 Using Local Variables and Arguments for PowerPC Assembly130 Specifying Instructions for PowerPC Assembly. 131 Specifying Operands for PowerPC Assembly . 132 Using registers . 132 Using labels . 132 Using variable names as memory locations . 133 Using immediate operands . 134 PowerPC Assembler Directives . 134 entry . 134 fralloc . 135 frfree . 136 machine . 136 smclass . 137 PowerPC Assembler Instructions . 138 6 MIPS Assembler Notes . 161 Overview of MIPS Assembler Notes. 161 Writing an Assembly Function . 161 Creating labels . 163 Using comments . 163 C, C++, and Assembly Language Reference CL–7 Using the preprocessor . 164 Creating a stack frame . 164 Specifying operands . 164 Using registers . ..