Jump to 
content
HP.com Home Products and Services Support and Drivers Solutions How to Buy
»  Contact HP

 

dec_c_help.HLP

Block

A block is a compound statement. It allows more than one statement to appear where a single statement ordinarily is used. It is made up of a list of declarations and statements, enclosed in braces: { [declaration ...] [statement ...] } The declaration list is optional; if it is included, all declarations of variables are local to the block and supersede previous declarations for the duration of the block. A block is entered normally when control flows into it, or when a goto statement transfers control to a label at the beginning of the block. Each time the block is entered normally, storage is allocated for auto or register variables. If, on the other hand, a goto statement transfers control to a label inside the block or if the block is the body of a switch statement, these storage allocations do not occur. Blocks can be used wherever single statements are valid -- for example, as the action clause of an if statement: if ( i < 1 ) { /* BEGINNING OF BLOCK */ char x; for (x = 'a'; x <= 'z'; x++) printf("char = %c\n", x); } /* END OF BLOCK */

Valid_File_Specifications

In HP C source programs, you can include both OpenVMS and UNIX* style file specifications. Combinations of the two specifications are not supported by HP C. Example of a valid UNIX* file specification: beatle!/dba0/lennon/songs.lis.3 Example of an invalid UNIX* file specification: BEATLE::DBA0:[LENNON.C]/songs.lis.3 ---------- * UNIX is a trademark of The Open Group.

Data_Types

The data type of an object must be specified in its declaration. The fundamental data types are the scalar types: short int 16-bit signed integer signed short int 16-bit signed integer unsigned short int 16-bit unsigned integer int 32-bit signed integer signed int 32-bit signed integer unsigned int 32-bit unsigned integer long int 32-bit signed integer signed long int 32-bit signed integer unsigned long int 32-bit unsigned integer long long int 64-bit signed integer signed long long int 64-bit signed integer unsigned long long int 64-bit unsigned integer char 8-bit signed integer signed char 8-bit signed integer unsigned char 8-bit unsigned integer wchar_t Long character (32-bit unsigned integer) float 32-bit (single-precision) floating-point number double 64-bit (double-precision) floating-point number long double 128-bit (double-precision) floating-point number long float Interchangeable with double, but usage is obsolete _Bool An unsigned int that has the value 0 or 1 _Imaginary A C99-specified data type. In HP C, use of the _Imaginary keyword produces a warning, which is resolved by treating it as an ordinary identifier. _Complex C99-specified data type available in all three precisions: float _Complex, double _Complex, or long double _Complex. A complex type has the same representation and alignment requirements as an array type containing exactly two elements of the corresponding real type; the first element is equal to the real part, and the second element to the imaginary part, of the complex number. Note: This complex data type is similar to the Fortran type, and has an associated header file, <complex.h>. Although the fundamental complex data types are implemented in the compiler, the run-time support will not be available until an OpenVMS Alpha release following Version 7.3. The signed keyword is the default. Declaring an object with int, for example, is equivalent to declaring it with signed int. However, char declarations should be explicitly declared, as the compiler offers command-line options to change the default. If in doubt, use signed char over char because signed char is more portable. Strings are arrays of characters terminated by the null character (\0). Also, view the contents of the <ints.h> header file for definitions of platform-specific integer types.

Additional Information on:

  • Array
  • enum
  • Pointer
  • Structure
  • typedef
  • Union
  • Void

  • Declarations

    Declarations specify the functions and variables referenced in a program. Declarations in C have the following syntax: declaration: declaration-specifiers [init-declarator-list]; declaration-specifiers: storage-class-specifier [declaration-specifiers] type-specifier [declaration-specifiers] type-qualifier [declaration-specifiers] init-declarator-list: init-declarator init-declarator-list, init-declarator init-declarator: declarator declarator = initializer Note the following items about the general syntax of a declaration: o The storage-class-specifier, type-qualifier, and type-specifier can be listed in any order. All are optional, but, except for function declarations, at least one such specifier or qualifier must be present. Placing the storage-class-specifier anywhere but at the beginning of the declaration is an obsolete style. o Storage-class keywords are auto, static, extern, and register. o Type qualifiers are const, volatile, __restrict, and __unaligned. o The declarator is the name of the object being declared. A declarator can be as simple as a single identifier, or can be a complex construction declaring an array, structure, pointer, union, or function (such as *x, tree(), and treebar[10]). o Initializers are optional and provide the initial value of an object. An initializer can be a single value or a brace-enclosed list of values, depending on the type of object being declared. o A declaration determines the beginning of an identifier's scope. o An identifier's linkage is determined by the declaration's placement and its specified storage class. Consider the following example: volatile static int var_number = 10; This declaration shows a qualified type (a type, int, with a type qualifier, volatile), a storage class (static), a declarator (data), and an initializer (10). This declaration is also a definition, because storage is reserved for the data object var_number. For more information, see HELP CC LANGUAGE_TOPICS DATA_TYPES, HELP CC LANGUAGE_TOPICS STORAGE_CLASSES, and HELP CC LANGUAGE_TOPICS TYPE_QUALIFIERS.

    Additional Information on:

  • Interpretation

  • Functions

    Functions consist of one or more blocks of statements that perform one logical operation. They can be called from other functions either in the same program or in different programs. A function may exchange values with the calling function by use of parameters. Function declarations have the following syntax: function_name() or function_name(arg1, arg2,...) or function_name(data-type arg1, data-type arg2,...) In the first form of the function declaration, the function takes no arguments. In the second form, the function takes arguments; the arguments are declared outside the parameter list. In the third form, the function declaration is a function prototype that specifies the type of its arguments in the identifier list; the prototype form is recommended. In all three cases, the parenthesis after the function name are required. HP C for OpenVMS Systems provides a library of common functions. These functions perform standard I/O operations, character and string handling, mathematical operations, miscellaneous system services, and UNIX* system emulation. For more information, see HELP CRTL. ---------- * UNIX is a trademark of The Open Group.

    Builtin_Functions

    Built-in functions allow you to directly access hardware and machine instructions to perform operations that are cumbersome, slow, or impossible in pure C. These functions are very efficient because they are built into the HP C compiler. This means that a call to one of these functions does not result in a reference to a function in the C run-time library or in your programs. Instead, the compiler generates the machine instructions necessary to carry out the function directly at the call site. Because most of these built-in functions closely correspond to single VAX, Alpha, or Itanium machine instructions, the result is small, fast code. Some of these functions (such as those that operate on strings or bits) are of general interest. Others (such as the functions dealing with process context) are of interest if you are writing device drivers or other privileged software. Some of the functions are privileged and unavailable to user mode programs. Be sure to include the <builtins.h> header file in your source program to access these built-in functions. HP C supports the #pragma builtins preprocessor directive for compatibility with VAX C, but it is not required. Some of the built-in functions have optional arguments or allow a particular argument to have one of many different types. To describe different valid combinations of arguments, the description of each built-in function may list several different prototypes for the function. As long as a call to a built-in function matches one of the prototypes listed, the call is valid. Furthermore, any valid call to a built-in function acts as if the corresponding prototype was in scope, so the compiler performs the argument checking and argument conversions specified by that prototype. The majority of the built-in functions are named after the machine instruction that they generate. For more information on these built-in functions, see the documentation on the corresponding machine instruction. In particular, see that reference for the structure of queue entries manipulated by the queue built-in functions.

    Additional Information on:

  • Alpha_Compatibility
  • __break
  • __break2
  • __CMP_SWAP_LONG
  • __CMP_SWAP_QUAD
  • __CMP_SWAP_LONG_ACQ
  • __CMP_SWAP_QUAD_ACQ
  • __CMP_SWAP_LONG_REL
  • __CMP_SWAP_QUAD_REL
  • __RETURN_ADDRESS
  • __dsrlz
  • __fc
  • __flushrs
  • __fwb
  • __getIndReg
  • __getReg
  • _InterlockedCompareExchange_acq
  • _InterlockedCompareExchange64_acq
  • _InterlockedCompareExchange_rel
  • _InterlockedCompareExchange64_rel
  • __invalat
  • __invala
  • __isrlz
  • __itcd
  • __itci
  • __itrd
  • __itri
  • __loadrs
  • __prober
  • __probew
  • __ptce
  • __ptcl
  • __ptcg
  • __ptcga
  • __ptri
  • __ptrd
  • __rum
  • __rsm
  • __setIndReg
  • __setReg
  • __ssm
  • __sum
  • __synci
  • __tak
  • __tpa
  • __thash
  • __ttag

  • Variable_Length_Argument_Lists

    The set of functions and macros defined and declared in the <varargs.h> and the <stdarg.h> header files provide a method of accessing variable-length argument lists. (Note that the <stdarg.h> functions are defined by the ANSI C standard and are, therefore, portable as compared with those defined in <varargs.h>.) The HP C RTL functions such as printf and execl, for example, use variable-length argument lists. User-defined functions with variable-length argument lists that do not use <varargs.h> or <stdarg.h> are not portable due to the different argument-passing conventions of various machines. To use these functions and macros in <stdarg.h>, you must include the <stdarg.h> header file with the following preprocessor directive: #include <stdarg.h> The <stdarg.h> header file declares a type (va_list) and three macros (va_start, va_arg, and va_end) for advancing through a list of function arguments of varying number and type. The macros have the following syntax: void va_start(va_list ap, parmN); type va_arg(va_list ap, type); void va_end(va_list ap); The va_start macro initializes the object ap of type va_list for subsequent use by va_arg and va_end. The va_start macro must be invoked before any access to the unnamed arguments. The parameter parmN is the identifier of the rightmost parameter in the variable parameter list of the function definition. If parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default arguments promotions, the behavior is undefined. The va_start macro returns no value. The va_arg macro expands to an expresion that has the type and value of the next argument in the call. The parameter ap is the same as the one initialized by va_start. Each invocation of va_arg modifies ap so that the values of successive arguments are returned in turn. The parameter "type" is a type name specified such that the type of a pointer to an object that has the specified type can be obtained by postfixing an asterisk (*) to "type". If there is no actual next argument, or if type is not compatible with the type of the next actual argument (as promoted according to the default argument promotions), the behavior is undefined. The first invocation of va_arg after that of va_start returns the value of the argument after that specified by parmN. Successive invocations return the values of the remaining arguments in turn. The va_end macro facilitates a normal return from the function whose variable argument list was referred to by the expansion of va_start that initialized the va_list ap object. The va_end macro can modify ap) so that it can no longer be used (without an intervening invocation of va_start). If there is no corresponding invocation of va_start or if va_end is not invoked before the return, the behavior is undefined. The va_end macro returns no value.

    Preprocessor

    The HP C preprocessor uses directives to affect the compilation of a source file. For HP C on OpenVMS systems, these directives are processed by an early phase of the compiler, not by a separate program. The preprocessor directives begin with a number sign (#) and do not end with a semicolon. The number sign must appear in the first column of the source line.

    Additional Information on:

  • Null_directive (#)
  • Conditional_Compilation
  • #define
  • #dictionary
  • #error
  • #include
  • #line
  • #module
  • #pragma
  • #undef

  • Predefined_Macros

    In addition to the ANSI-compliant, implementation-independent macros described in the HP C Language Reference Manual, The HP C compiler provides the following predefined macros:

    Additional Information on:

  • System_Identification_Macros
  • Compiler_Mode_Macros
  • Floating_Point_Macros
  • RTL_Standards_Macros
  • __HIDE_FORBIDDEN_NAMES
  • CC$gfloat
  • __DATE__
  • __FILE__
  • __LINE__
  • __TIME__

  • Predeclared_Identifiers

    Additional Information on:

  • __func__

  • Statements

    Statements are the executable instructions performed by the program. Statements produce values and control program flow. A group of statements enclosed in braces makes up a block. Any valid expression or declaration terminated by a semicolon is considered a statement. The statements that control program flow are described in further HELP frames. See also HELP CC LANGUAGE_TOPICS DECLARATION and HELP CC LANGUAGE_TOPICS PREPROCESSOR.

    Additional Information on:

  • break
  • continue
  • do
  • for
  • goto
  • if
  • Labeled
  • Null
  • return
  • switch
  • while

  • Storage_Classes

    The storage class of a variable determines when its storage is allocated, whether its contents are preserved across different blocks or functions, and what link-time scope the variable has. Auto variables are allocated at run time. They are not preserved across functions. Auto is the default storage class for variables declared within a function. Extern variables are allocated at compile time. They are preserved across functions. There can be only 65,532 extern variables per program. Extern is the default storage class for variables declared outside a function. Globaldef, globalref, and globalvalue variables are allocated at compile time. They are preserved across functions. The number of global symbols is unlimited. Register variables are allocated at run time. They cannot be referenced from other separately compiled functions. Static variables are allocated at compile time. If externally declared, they retain their values across functions. If internally declared (inside of a function), they cannot be referenced from other functions; if control passes from the defining function, to other functions, and then passed back to the defining function, the variable retains its previous value and is not reinitialized.

    Type_Qualifiers

    Data-type qualifiers affect the allocation or access of data storage. The data-type qualifiers are const, volatile, __restrict, and __unaligned.

    Additional Information on:

  • const
  • volatile
  • __restrict
  • __unaligned

  • Storage_Class_Modifiers

    The storage-class modifiers allow individual attributes of a variable to change without changing the other default attributes connected with a given storage class. Storage-class keywords and storage-class modifiers can be specified in either order. Syntax: modifier storage_class_keyword identifier; If you specify a storage-class modifier but not a storage class keyword, the storage class defaults to extern.

    Additional Information on:

  • noshare
  • readonly
  • _align
  • __align
  • __forceinline
  • __inline
  • inline

  • Privacy statement Using this site means you accept its terms
    © 2007 Hewlett-Packard Development Company, L.P.