HP C User's Guide for Openvms Systems
Total Page:16
File Type:pdf, Size:1020Kb
HP C User’s Guide for OpenVMS Systems Order Number: AA–PUNZM–TK January 2005 This guide describes using the HP C compiler on OpenVMS systems. It contains information on HP C program development in the OpenVMS environment, HP C features specific to OpenVMS systems, and cross-system portability concerns. Revision/Update Information: This revised guide supersedes the Compaq C User’s Guide for OpenVMS Systems Order No. AA–PUNZL–TK, Version 6.5. Operating System and Version: OpenVMS I64 Version 8.2 or higher OpenVMS Alpha Version 7.3-2 or higher Software Version: HP C Version 7.1 for OpenVMS Systems Hewlett-Packard Company Palo Alto, California © Copyright 2005 Hewlett-Packard Development Company, L.P. Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor’s standard commercial license. The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein. UNIX is a registered trademark of The Open Group. X/Open is a registered trademark of X/Open Company Ltd. in the UK and other countries. Intel and Itanium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Printed in the US This document is available on CD-ROM. ZK5492 This document was prepared using DECdocument, Version 3.3-1n. Contents Preface ..................................................... xxi 1 Developing HP C Programs 1.1 DCL Commands for Program Development ................. 1–1 1.2 Creating an HP C Program . ........................... 1–3 1.2.1 Using TPU ....................................... 1–4 1.2.2 The EVE Interface to TPU ........................... 1–4 1.3 Compiling an HP C Program . ........................... 1–4 1.3.1 The CC Command ................................. 1–5 1.3.1.1 Including Header Files ........................... 1–6 1.3.1.2 Listing Header Files . ........................... 1–8 1.3.2 Compilation Modes ................................ 1–9 1.3.3 Microsoft Compatibility Compilation Mode .............. 1–12 1.3.3.1 Unnamed Nested struct or union Members . .......... 1–12 1.3.3.2 Block Scope Declaration of static Functions . .......... 1–12 1.3.3.3 Treat &* as Having No Effect . ................... 1–12 1.3.3.4 char is Not Treated as a Unique Type ............... 1–13 1.3.3.5 Double Semicolons in Declarations ................. 1–13 1.3.3.6 Declaration without a Type ....................... 1–13 1.3.3.7 Enumerators in an Enumeration Declaration ......... 1–13 1.3.3.8 Useless Typedefs ............................... 1–13 1.3.3.9 Unrecognized Pragmas Accepted ................... 1–14 1.3.4 CC Command Qualifiers . ........................... 1–14 1.3.5 Compiler Diagnostic Messages ........................ 1–83 1.4 Linking an HP C Program . ........................... 1–84 1.4.1 The LINK Command ............................... 1–85 1.4.2 LINK Command Qualifiers .......................... 1–86 1.4.3 Linker Input Files ................................. 1–87 1.4.4 Linker Output Files ................................ 1–88 1.4.5 Linking Against Object Module Libraries and Shareable Images .......................................... 1–88 1.4.6 Object Module Libraries . ........................... 1–89 iii 1.4.7 Linker Error Messages . ........................... 1–90 1.5 Running an HP C Program . ........................... 1–91 1.6 Passing Arguments to the main Function .................. 1–93 1.7 64-bit Addressing Support . ........................... 1–95 1.7.1 Qualifiers and Pragmas . ........................... 1–96 1.7.1.1 The /POINTER_SIZE Qualifier . ................... 1–96 1.7.1.2 The _ _INITIAL_POINTER_SIZE Macro . .......... 1–97 1.7.1.3 The /CHECK=POINTER_SIZE Qualifier . .......... 1–97 1.7.1.4 Pragmas . ................................... 1–98 1.7.2 Determining Pointer Size . ........................... 1–98 1.7.2.1 Special Cases .................................. 1–100 1.7.2.2 Mixing Pointer Sizes . ........................... 1–101 1.7.3 Header File Considerations .......................... 1–101 1.7.4 Prologue/Epilogue Files . ........................... 1–102 1.7.4.1 Rationale . ................................... 1–102 1.7.4.2 Using Prologue/Epilogue Files . ................... 1–103 1.7.5 Avoiding Problems ................................. 1–104 1.7.6 Examples ........................................ 1–105 2 Using OpenVMS Record Management Services 2.1 RMS File Organization ................................ 2–2 2.1.1 Sequential File Organization ......................... 2–2 2.1.2 Relative File Organization ........................... 2–3 2.1.3 Indexed File Organization ........................... 2–3 2.2 Record Access Modes .................................. 2–4 2.3 RMS Record Formats .................................. 2–5 2.4 RMS Functions . ................................... 2–5 2.5 Writing HP C Programs Using RMS . ................... 2–7 2.5.1 Initializing File Access Blocks ........................ 2–9 2.5.2 Initializing Record Access Blocks . ................... 2–10 2.5.3 Initializing Extended Attribute Blocks .................. 2–10 2.5.4 Initializing Name Blocks . ........................... 2–11 2.6 RMS Example Program ................................ 2–12 3 Using HP C in the Common Language Environment 3.1 Basic Calling Standard Conventions . ................... 3–2 3.1.1 Register and Stack Usage ........................... 3–3 3.1.2 Return of the Function Value ......................... 3–5 3.1.3 The Argument List ................................. 3–5 3.2 Specifying Parameter-Passing Mechanisms ................. 3–7 3.2.1 Passing Arguments by Immediate Value ................ 3–8 iv 3.2.2 Passing Arguments by Reference . ................... 3–12 3.2.3 Passing Arguments by Descriptor . ................... 3–14 3.2.4 HP C Default Parameter-Passing Mechanisms . .......... 3–20 3.3 Interlanguage Calling ................................. 3–20 3.3.1 Calling HP FORTRAN . ........................... 3–21 3.3.2 Calling VAX MACRO ............................... 3–26 3.3.3 Calling HP BASIC ................................. 3–30 3.3.4 Calling HP Pascal ................................. 3–33 3.4 Sharing Global Data .................................. 3–39 3.4.1 Sharing Program Sections with FORTRAN Common Blocks .......................................... 3–40 3.4.2 Sharing Program Sections with PL/I Externals . .......... 3–42 3.4.3 Sharing Program Sections with MACRO Programs ........ 3–44 3.5 OpenVMS Run-Time Library Routines . ................... 3–45 3.6 OpenVMS System Services Routines . ................... 3–46 3.7 Calling Routines . ................................... 3–47 3.7.1 Determining the Type of Call ......................... 3–47 3.7.2 Declaring an External Routine and Its Arguments ........ 3–47 3.7.3 Calling the External Routine ......................... 3–48 3.7.4 System Routine Arguments .......................... 3–48 3.7.5 Symbol Definitions ................................. 3–52 3.7.6 Condition Values .................................. 3–52 3.7.7 Checking System Service Return Values ................ 3–53 3.8 Variable-Length Argument Lists in System Services .......... 3–55 3.9 Return Status Values .................................. 3–57 3.9.1 Format of Return Status Values . ................... 3–57 3.9.2 Manipulating Return Status Values . ................... 3–59 3.9.3 Testing for Success or Failure ........................ 3–61 3.9.4 Testing for Specific Return Status Values ............... 3–62 3.10 Examples of Calling System Routines . ................... 3–63 4 Data Storage and Representation 4.1 Storage Allocation . ................................... 4–1 4.2 Standard-Conforming Method of Controlling External Objects . ........................................... 4–3 4.3 Global Storage Classes ................................. 4–4 4.3.1 The globaldef and globalref Specifiers .................. 4–4 4.3.2 Comparing the Global and the External Storage Classes . 4–7 4.3.3 The globalvalue Specifier . ........................... 4–9 4.4 Storage-Class Modifiers ................................ 4–10 4.4.1 The noshare Modifier ............................... 4–10 4.4.2 The readonly Modifier . ........................... 4–11 v 4.4.3 The _align Modifier ................................ 4–12 4.5 Floating-Point Numbers (float, double, long double) .......... 4–12 4.6 Pointer Conversions ................................... 4–15 4.7 Structure Alignment .................................. 4–15 4.7.1 Bit-Field Alignment ................................ 4–17 4.7.2 Bit-Field Initialization . ........................... 4–17 4.7.3 Variant Structures and Unions ....................... 4–18 4.8 Program Sections . ................................... 4–21 4.8.1 Attributes of Program Sections ....................... 4–21 4.8.2 Program Sections Created by HP C ................... 4–22 5 Preprocessor Directives 5.1 CDD/Repository Extraction (#dictionary) ................... 5–2 5.2 File Inclusion (#include) ................................ 5–2 5.2.1 Inclusion