C/C++ Programmer's Guide (G06.25+)
Running and Debugging C and C++ Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
19-11
Debugging C and C++ Programs
•
Ensure that the type of a function call argument matches the defined type of its
associated parameter. The compiler issues the following warning message for
argument-parameter mismatches:
Warning 86: argument "name" conflicts with formal definition
•
Write function prototypes for all user-written functions that don’t have prototypes.
The compiler issues the following warning message for function calls that don’t
have corresponding function prototypes:
Warning 95: prototype function declaration not in scope:
"function-name"
•
Ensure that the formal and actual parameters of pointer types are matched. The
compiler issues the following warning message if pointers do not match:
Warning 30: pointers do not point to same type of object
For example:
int func1(short *);
In the 16-bit data model and the large-memory model, you can pass to func1 a
pointer of type short or int and get the correct results. In the 32-bit data model,
you can pass to func1 only a pointer of type short; a pointer of type int
generates incorrect results.
Parameter mismatch is most often an issue for Guardian system procedures and
external TAL routines.
•
Ensure that literals do not cause type mismatches.
#include <cextdecs(MONITORCPUS)>
...
short get_cpu_number;
MONITORCPUS(0x8000 >> get_cpu_number);
In the 32-bit data model, if get_cpu_number is equal to zero, an arithmetic
overflow occurs because the compiler generates code to convert an unsigned 32-
bit integer to a 16-bit signed integer. Note that cextdecs does not use the type
unsigned short.
•
Avoid using the type int in your program, if possible. Use type long or short
instead. However, if you want to keep your program data-model independent, you
cannot avoid using type int completely. For example, C library calls, bit-fields,
TCP/IP sockets library functions, and Guardian system procedures might require
type int.
Debugging C and C++ Programs
To debug C and C++ programs, you can use several debuggers:
•
Debug on G-series systems
•
Inspect on G-series or H-series systems