B Common Pitfalls

This appendix contains some of the most common pitfalls you might encounter while using DEC 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, DEC 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 ANSI Standard restricts allowable automatic aggregate initializion. The DEC C compiler does not have this restriction in /STANDARD=VAXC mode. Use any of the following solutions.


Previous Page | Next Page | Table of Contents | Index