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

 

HP C

HP C
User's Guide for OpenVMS Systems


Previous Contents Index

A.2.7 <stdio.h>

The <stdio.h> header file now defines the type size_t and no longer includes <stdarg.h> . The v*printf functions are now prototyped using the type that va_list is defined to be (that is, char * ).

In strict ANSI C mode, the following macros are not visible: TRUE , FALSE , SEEK_EOF , OPEN_MAX , L_ctermid , L_cuserid , L_lcltmpnam , L_nettmpnam , and FILE_TYPE . In strict ANSI C mode, the following functions are not visible: fgetname , fdopen , getw , and putw .

The rename function is added.

The fflush function is modified so that a null argument causes it to flush all files.

The printf function is modified to provide the following support:

  • The %i conversion is supported.
  • The "0" flag works properly in conjunction with other flags and with all conversion specifiers. The long double type and the h modifier are now supported.
  • The %d and %i specifiers interpret the precision specification.

The scanf function is modified to handle white space as specified by the C Standard. The %p specifier is added. The L flag for long double is added.

The clearerr , feof , and ferror macros are now provided as both macros and functions. By default, they are accessed as macros. To access them as functions, perform an #undef on the macro of the same name. For example:


#undef clearerr 

A.2.8 <stdlib.h>

The <stdlib.h> header file is modified to define size_t and wchar_t directly, rather than including <stddef.h> . The names of the DIV_T and LDIV_T structures now begin with underscores.

The MB_CUR_MAX macro is added.

The multibyte character and string functions mblen , mbtowc , wctomb , mbstowcs and wcstombs are added as specified in Sections 4.10.7 and 4.10.8 of the C Standard.

The abort() function is changed to only raise a SIGABRT signal.

A.2.9 <string.h>

The strcoll and strxfrm functions are added as specified in the C Standard, Sections 4.11.4.3 and 4.11.4.5.

A.2.10 <time.h>

In strict and relaxed modes, the following changes apply to the <time.h> header file:

  • CLOCKS_PER_SEC is defined instead of CLK_TCK .
  • The size_t and time_t types are defined, and the <types.h> and <timeb.h> header files are not included.
  • The times and ftime functions, and the struct tbuffer , tbuffer_t , and tm_t types must not be defined in your source code.

The mktime and strftime functions are added as specified in the C Standard, Sections 4.12.2.3 and 4.12.3.5, respectively.

A.3 Unsupported Features

HP C for OpenVMS Systems does not support parallel processing on either OpenVMS VAX or OpenVMS Alpha systems and, therefore, does not support the following qualifiers and preprocessor directives:

/[NO]PARALLEL
/SHOW=NODECOMPOSITION
#pragma ignore_dependency
#pragma safe_call
#pragma sequential_loop


Appendix B
Common Pitfalls

This appendix contains some of the most common pitfalls you might encounter while using HP C. Symptoms, examples, and solutions are described.

Symptom:

The compiler generates an "Insufficient Virtual Memory" error.

Solution:

Increase the PAGEFILEQUO process quota and/or the VIRTUALPAGCNT sysgen parameter.

Symptom:

The compiler does not recognize expected routine entry points.

Example:


$ type main.c 
main() 
{ 
  exit(1); 
} 
$ cc main.c 
exit(1); 
..^ 
%CC-I-IMPLICITFUNC, In this statement, the identifier 
exit is implicitly declared as a function. 

Solutions:

  1. In ANSI mode, include function prototypes (such as #include <stdlib.h> ) in this example.
  2. Compile using the /STANDARD=VAXC qualifier.

Symptom:

The compiler generates a %CC-E-NOTCOMPAT error message for seemingly correct code.

Example:


$ type main.c 
void foo(short a); 
void foo(a) 
  short a; 
{} 
$ cc main.c 
                   
 
void foo(a) 
.....^ 
 
%CC-E-NOTCOMPAT, In this declaration, the type of foo is not compatible 
with the types of previous declarations of foo. 

This example represents a mixing of new-style function prototypes and old-style function declarations. In the following declaration, the argument a gets widened to int on entry to foo before being converted to type short :


void foo(a) 
short a; 

Consequently the compiler detects a type mismatch. The example can be generalized to float variables, or any combination of ( unsigned ) char or short arguments.

Solutions:

  1. Replace the new-style function prototype with an old-style function definition:


    void foo(); 
    void foo(a) 
    short a; 
    {} 
    

  2. Replace the old-style function declaration with a new-style function declaration:


    void foo(short a); 
    void foo(short a) 
    {} 
    

Symptom:

Include-file lookups do not include the anticipated files.

Example:

By default, HP C for OpenVMS Systems first searches the directory containing the top-level source file. Consider the following files and the #include statements they contain:


[]main.c 
   #include "[.sub1]a.h" 
 
[.sub1]a.h 
   #include "b.h" 
                                 
[.sub1]b.h 
   "In [.sub1]" 
 
[.sub2]b.h 
  "In [.sub2]" 

Compiling with the following command includes the [.sub2]b.h header file:


cc/include=[.sub2]main.c 

Solution:

Specify /NESTED_INCLUDE_DIRECTORY in order to first search the directory containing the top-level source file (not the directory of the source file containing the #include directive).

Symptom:

VAX C extensions to the language are not accepted by the compiler.

Example:


int _align (word) w1; 
....^ 
%CC-W-ALIGNEXT, _align is a language extension. 

Solution:

Compile using the /STANDARD=VAXC qualifier.

Symptom:

The compiler generates a ADDRCONSTEXT (warning in /STANDARD=RELAXED mode and error in /STANDARD=ANSI mode) for seemingly correct code.

Example:


$ type main.c 
struct dsc$descriptor_s 
{ 
  unsigned short dsc$w_length; 
  unsigned char dsc$b_dtype; 
  unsigned char dsc$b_class; 
  char *dsc$a_pointer; 
}; 
 
main() 
{ 
  char name[5]; 
  struct dsc$descriptor_s name_dsc = { 
  sizeof(name)-1, 14, 1, name }; 
} 
 
$ cc main.c 
 
sizeof(name)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, name }; 
..............................................^ 
%CC-W-ADDRCONSTEXT, In the initializer for name_dsc.dsc$a_pointer, 
"name" does not have a constant address, but occurs in a context that 
requires an address constant. This is an extension of the language. 

Solution:

Section 3.5.7 of the C Standard restricts allowable automatic aggregate initializion. The HP C compiler does not have this restriction in /STANDARD=VAXC mode. Use any of the following solutions.

  • Declare the array name to be static:


    static char name[5]; 
    

  • Compile in /STANDARD=VAXC mode.
  • Compile with /WARNING=DISABLE=ADDRCONSTEXT.
  • Insert the #pragma [no]standard preprocessor directive to suppress the warning message:


    #pragma __nostandard 
    struct dsc$descriptor_s name_dsc = { 
        sizeof(name)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, name }; 
         } 
    #pragma __standard 
    


Appendix C
Programming Tools

This appendix provides information on tools that you can use to develop and to refine your HP C programs. Some of the products described ship with the OpenVMS operating system; others must be purchased separately. The following products are described in this appendix:

C.1 OpenVMS Debugger

A debugger is a tool to help you locate run-time errors quickly. It enables you to observe and manipulate the program's execution interactively, step by step, until you locate the point at which the program stopped working correctly.

The OpenVMS Debugger (provided with the OpenVMS operating system) is a symbolic debugger. You can refer to program locations by the symbols (names) you used for those locations in your program: the names of variables, routines, labels, and so on. You do not have to use virtual addresses to refer to memory locations.

If your program is written in more than one language, you can change from one language to another in the course of a debugging session. The current source language determines the format used for entering and displaying data, as well as other features that have language-specific settings (for example, comment characters, operators and operator precedence, and case sensitivity or insensitivity).

For information on the debugger, see the OpenVMS Debugger Manual.

The following sections provide language-specific information on the
OpenVMS Debugger.

C.1.1 Compiling and Linking to Prepare for Debugging

The following example shows how to compile and link a HP C program (consisting of a single compilation unit named INVENTORY) so that you will be able to use the debugger:


$ CC/DEBUG/NOOPTIMIZE INVENTORY
$ LINK/DEBUG INVENTORY

The /DEBUG qualifier on the CC command causes the compiler to write the debug symbol records associated with INVENTORY.C into the object module, INVENTORY.OBJ. These records allow you to use the names of variables and other symbols declared in INVENTORY with debugger commands. (If your program has several compilation units, you must compile each unit that you want to debug with the /DEBUG qualifier.)

You should use the /NOOPTIMIZE qualifier when you compile in preparation for debugging. Without this qualifier, the resulting object code is optimized, which may cause the contents of some program locations to be inconsistent with what you might expect from the source code. (After the program has been debugged, you will probably want to recompile it without the /NOOPTIMIZE qualifier, because optimization might reduce a program's size and increase the execution speed.)

The /DEBUG qualifier on the LINK command causes the linker to include all symbol information that is contained in INVENTORY.OBJ in the executable image. The qualifier also causes the OpenVMS image activator to start the debugger at run time. (If your program has several object modules, you might need to specify other modules in the LINK command.)

C.1.2 Starting and Terminating a Debugging Session

Before you invoke the debugger, enter the following command to check the current debugger configuration:


$ SHOW LOGICAL DBG$PROCESS
%SHOW-S-NOTRAN, no translation for logical name DBG$PROCESS

If DBG$PROCESS has a value other than undefined (as in the previous example) or DEFAULT, enter the following command to change this value:


$ DEFINE DBG$PROCESS DEFAULT

Enter the DCL command RUN to invoke the debugger. The following message appears on your screen:


$ RUN INVENTORY
                     OpenVMS DEBUG Version 6.n
%DEBUG-I-INITIAL, language is C, module set to 'INVENTORY'
DBG>

You can now enter debugger commands at the DBG> prompt. At this point, if you enter the GO command, program execution begins and continues until it is forced to pause or stop (for example, if the program prompts you for input, or an error occurs).

To interrupt a debugging session and return to the debugger prompt, press Ctrl/C. This is useful if, for example, your program loops or you want to interrupt a debugger command that is still in progress. For example:


DBG> GO
    .
    .
    .
(infinite loop) 
[Ctrl/C]
Interrupt
%DEBUG-W-ABORTED, command aborted by user request
DBG> 

The following message indicates that your program has completed successfully:


%DEBUG-I-EXITSTATUS, is '%SYSTEM-S-NORMAL, normal successful completion'
DBG> 

To end a debugging session, enter the EXIT command at the DBG> prompt or press Ctrl/Z:


DBG> EXIT
$

C.1.3 Notes on HP C Support

In general, the OpenVMS Debugger supports the data types and operators of
HP C and of the other debugger-supported languages. To get information on the supported data types and operators of any of the languages, enter the HELP LANGUAGE command at the DBG> prompt.

The following sections present HP C specific debugging examples.

C.1.3.1 Debugger Command-Line Options

HP C provides a set of debugger options that you can specify to the /DEBUG qualifier to the CC command. These options alter the types of information that the compiler places in the object module for use by the OpenVMS Debugger. The debugger options include using traceback records, using the symbol table, and enabling the debugger to step into inline functions. For information about these options, see Section 1.3.4.

C.1.3.2 Accessing Scalar Variables

The EXAMINE command displays scalar variables of any HP C data type. Reference scalar variables in the same case that you declare them, using the
HP C syntax for such references.

Example C-1 shows the HP C program SCALARS.C used in the examples that follow.

Example C-1 Debugging Sample Program SCALARS.C

/*  SCALARS.C  This program defines a large number of          * 
 *             variables to demonstrate the effect             * 
 *             of the various STEP debugger commands.          */ 
 
main() 
{ 
   static float light_speed;       /*  Define the variable.    */ 
   static double speed_power; 
   static unsigned ui; 
   static long li; 
   static char ch; 
   static enum primary { red, yellow, blue } color; 
 
   static long *ptr; 
 
 
   light_speed = 3.0e10; 
   speed_power = 3.1234567890123456789e10; 
   ui = -438394; 
   li = 790374270; 
   ch = 'A'; 
   color = blue; 
   ptr = &li; 
} 

The following debugging examples are based on executing SCALARS.EXE and show the commands used to access variables of scalar data type.

The debugger command SHOW SYMBOL/TYPE displays the data type of one variable:


DBG> show symbol/type color
data SCALARS\main\color
    enumeration type (primary, 3 elements), size: 4 bytes

The following debugging commands set a breakpoint before the end of the program and execute the program up to the breakpoint. The program initializes the variables declared in main :


DBG> set break %line 22
DBG> go
break at SCALARS\main\%LINE 22
    22: }

The EXAMINE command displays the contents of the variables listed. The char variables are interpreted by the debugger as byte integers, not ASCII characters:


DBG> examine li, ui, light_speed, speed_power, ch, color, *ptr
SCALARS\main\li:        790374270
SCALARS\main\ui:        4294528902
SCALARS\main\light_speed:       3.0000001E+10
SCALARS\main\speed_power:       31234567890.12346
SCALARS\main\ch:        65
SCALARS\main\color:     blue
*SCALARS\main\ptr:       790374270

To display the contents of ch as a character, you must use the /ASCII qualifier:


DBG> examine/ascii ch
SCALARS\main\ch:      "A"

The DEPOSIT command loads the value single_quote> z ' in the variable ch ; the EXAMINE command shows that single_quote> z ' has replaced the previous contents of the variable ch . Again, use the /ASCII qualifier to translate the byte integer into its ASCII equivalent:


DBG> deposit/ascii ch = 'z'
DBG> examine/ascii ch
SCALARS\main\ch:        "z"
DBG>

C.1.3.3 Accessing Arrays

With the EXAMINE command, you can look at the values in arrays using HP C syntax for array references. You can examine an entire array by giving the array identifier. You can examine individual elements of the array using the array operator ([ ]). Array elements can have any data type.

Consider the following declaration:


int  arr[10]; 

This declares an array of 10 elements, arr[0] through arr[9] .

Example C-2 shows the HP C program ARRAY.C used in the examples that follow.

Example C-2 Debugging Sample Program ARRAY.C

/*  ARRAY.C  This program increments an array to               * 
 *           demonstrate the access of arrays in HP C.        */ 
 
main() 
{ 
    int i; 
    static int arr[10]; 
    for (i=0; i<10; i++) 
          arr[i]=i; 
} 

The examples that follow are based on executing ARRAY.EXE and show the commands used to access variable arrays. (Note: Compile ARRAY.C with the /NOOPT qualifier for the examples to work as described.)

The following commands set a breakpoint at the last line in the program and execute the program to that point:


DBG> set br  %line 10
DBG> go
break at ARRAY\main\%LINE 10
    10: }

By specifying the variable identifier, you can look at the entire array:


DBG> examine arr
ARRAY\main\arr
    [0]:        0
    [1]:        1
    [2]:        2
    [3]:        3
    [4]:        4
    [5]:        5
    [6]:        6
    [7]:        7
    [8]:        8
    [9]:        9

You can examine individual elements of the array by using the bracket operator to specify the subscript of the element. Pressing Return (the debugger's address reference operator) in an EXAMINE command displays the next element of the array. Using the up-arrow address reference operator (^) displays the previous member of the array:


DBG> examine arr[5]
ARRAY\main\arr[5]:      5
DBG> examine [Return]
ARRAY\main\arr[6]:      6
DBG> examine ^
ARRAY\main\arr[5]:      5


Previous Next Contents Index

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