|
|
HP CLanguage Reference ManualOrder Number: AA-PUNDJ-TK
January 2005
This document is the language reference manual for HP C.
Revision Update Information:
This manual supersedes the
Software Version:
HP C Version 7.1 for OpenVMS Systems
© 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. Intel and Itanium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. 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. Printed in the US
This document is available on CD-ROM. This document was prepared using DECdocument, Version V3.3-1e.
PrefaceThis manual provides reference information for using the HP C language on HP systems. HP C is an ANSI compliant C compiler for the OpenVMS operating system on VAX, Alpha, and Intel Itanium processors and for the Tru64 UNIX operating system on Alpha processors. HP OpenVMS Industry Standard 64 for Integrity Servers is the full product name of the OpenVMS operating system on Intel Itanium processors. The shortened forms, OpenVMS I64 and I64, are also used throughout this manual. HP C is compliant with the International Standards Organization (ISO) C Standard (ISO 9899:1990[1992]), formerly the American National Standard for Information Systems-Programming Language C (document number: X3.159-1989). By the use of command-line options, HP C is compatible with older dialects of C, including common usage C (Kernighan and Ritchie C) and VAX C. This manual is based on the ISO C Standard (ISO 9899:1990[1992]), formerly the ANSI X3J11 committee's standard for the C programming language (called the ANSI C standard in this manual). 1 All library functions and language extensions to the ANSI C standard are also described. You may send comments or suggestions regarding this manual or any HP C document by sending electronic mail to the following Internet address:
Intended AudienceThis manual is intended for programmers who need reference information on the HP C (formerly Compaq C) language. There is little task-oriented material or platform-specific material in this manual; for that type of information, see your platform-specific HP C documentation (user's guide and online help for OpenVMS systems, programmer's guide and reference pages for Tru64 UNIX systems.) Purpose of the ANSI StandardThe ANSI C standard was developed by a committee of program developers and knowledgeable C users to address the problems caused by inexact specification of the C language. These problems were primarily related to portability of programs between different types of machines. The committee analyzed the language for areas where its syntax and semantics were vague or indeterminate, and then chose precise definitions for those C constructs. The result is an unambiguous, machine-independent definition. The ANSI C standard states that it: " specifies the form and establishes the interpretation of programs expressed in the programming language C. [The standard's] purpose is to promote portability, reliability, maintainability, and efficient execution of C language programs on a variety of computing systems. " The standard specifies:
The ANSI C standard does not specify:
Manual StructureThis manual has the following chapters and appendixes: Chapter 1 describes the elements of the C language. Chapter 2 discusses some of the basic concepts underlying the C language. Chapter 3 explains HP C data types and type qualifiers. Chapter 4 describes the declaration of identifiers in HP C. The declaration of constants, variables, structures, unions, pointers, and arrays is covered. Chapter 5 describes function calls, function declarations, function definitions, function parameters, and function arguments. Chapter 6 discusses the types of expressions you can build in C. It also explains the effects of operators available in C, including unary, binary, conditional, primary, and postfix operators. Chapter 7 describes the C statements that provide flow control, conditional executions, looping, and interruption. Chapter 8 explains the purpose of the C preprocessor directives and predefined macros. Chapter 9 lists and describes the functions, macros, and types in the ANSI C standard library, arranged by header file. Appendix A provides a syntax summary of all C language constructs. Appendix B describes the extent of the ANSI conformance of HP C, including exceptions and extensions to the standard. Appendix C provides the ASCII octal, decimal, and hexadecimal equivalents for each character in the ASCII character set. Appendix D lists the common C extensions supported by HP C using the common C compatibility option. Appendix E lists the VAX C extensions supported by HP C using the VAX C compatibility option. Associated DocumentsYou may find the following documents useful when programming in HP C:
Conventions Used in This Document
New and Changed FeaturesHP C Version 7.1 runs on OpenVMS Alpha and OpenVMS Industry Standard 64 systems. The compiler behaves much the same on both systems, with some differences, primarily in the support for #pragma linkage , built-in functions, default floating-point representation, and predefined macros. These differences are noted in the relevant sections of the documentation.
Chapter 1
|
static int x=0; /* Could also be written "static int x = 0;" */ |
The compiler breaks the previous line into the following tokens (shown one per line):
static int x = 0 ; |
As the compiler processes the input character stream, it identifies tokens and locates error conditions. The compiler can identify three types of errors:
char x[3] = (1,2,3); |
int *x = 5.7; |
Logical errors are not identified by the compiler.
An important concept throughout C is the idea of a compilation unit, which is one or more files compiled by the compiler.
The ANSI C standard refers to compilation units as translation units. This text treats these terms as equivalent. |
The smallest acceptable compilation unit is one external definition.
The ANSI C standard defines several key concepts in terms of
compilation units. Section 2.2 discusses compilation units in detail.
A compilation unit with no declarations is accepted with a compiler
warning in all modes except for the strict ANSI standard mode.
A character set defines the valid characters that can be used in source programs or interpreted when a program is running. The source character set is the set of characters available for the source text. The execution character set is the set of characters available when executing a program. The source character set does not necessarily match the execution character set; for example, when the execution character set is not available on the devices used to produce the source code.
Different character sets exist; for example, one character set is based on the American Standard Code for Information Interchange (ASCII) definition of characters, while another set includes the Japanese kanji characters. The character set in use makes no difference to the compiler; each character simply has a unique value. C treats each character as a different integer value. The ASCII character set has fewer than 255 characters, and these characters can be represented in 8 bits or less. However, in some extended character sets, so many characters exist that some characters' representation requires more than 8 bits. A special type was created to accommodate these larger characters, called the wchar_t (or wide character) type. Section 1.9.3.1 discusses wide characters further.
Most ANSI-compatible C compilers accept the following ASCII characters for both the source and execution character sets. Each ASCII character corresponds to a numeric value. Appendix C lists the ASCII characters and their numeric values.
a b c d e f g h i j k l m n o p q r s t u v w x y z |
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
0 1 2 3 4 5 6 7 8 9 |
! # % ^ & * ( ) - _ = + ~ ' " : ; ? / | \ { } [ ] , . < > $ |
Space | ( ) |
Horizontal tab | (\t) |
Form feed | (\f) |
Vertical tab | (\v) |
New-line character | (\n) |
In character constants and string literals, characters from the execution character set can also be represented by character or numeric escape sequences. Section 1.9.3.3 and Section 1.9.3.4 describe these escape sequences.
The ASCII execution character set also includes the following control characters:
The null character is a byte or wide character with all bits set to 0. It is used to mark the end of a character string. Section 1.8 discusses character strings in more detail.
The new-line character splits the source character stream into separate lines for greater legibility and for proper operation of the preprocessor.
Sometimes a line longer than the terminal or window width must be interpreted by the compiler as one logical line. One logical line can be typed as two or more lines by appending the backslash character ( \ ) to the end of the continued lines. The backslash must be immediately followed by a new-line character. The backslash signifies that the current logical line continues on the next line. For example:
#define ERROR_TEXT "Your entry was outside the range of \ 0 to 100." |
The compiler deletes the backslash character and the adjacent new-line character during processing, so that this line becomes one logical line, as follows:
#define ERROR_TEXT "Your entry was outside the range of 0 to 100." |
A long string can be continued across multiple lines by using the backslash-newline line continuation feature, but the continuation of the string must start in the first position of the next line. In some cases, this destroys the indentation scheme of the program. The ANSI C standard introduces another string continuation mechanism to avoid this problem. Two string literals, with only white space separating them, are combined to form one logical string literal. For example:
printf ("Your entry was outside the range of " "0 to 100.\n"); |
The maximum logical line length is 32,767 characters.
Next | Contents | Index |
|