IBM
Contents Index Previous Next



Error Handling


The input headers to CPP2SDL have in many cases been compiled with a C/C++ compiler previously, and it should then be relatively uncommon that CPP2SDL will have to issue any error messages. However, differences in language support, and inappropriate preprocessor settings, are common sources for error reports also from input files that otherwise are perfectly correct.

If CPP2SDL finds an error in the input, a message will be printed that briefly describes the reason for the error.

Note:

The error messages produced by CPP2SDL are often less descriptive than the corresponding error messages from a C/C++ compiler. If CPP2SDL reports errors in a header file, it is therefore a good idea to run a C/C++ compiler on the same header file to get more information about the reason for the error.

The format of printed error messages are described in Source and Error References.

CPP2SDL performs a complete syntactic analysis of the input C/C++ code, and syntax errors are reported as shown in Example 142 below.

Example 142 : Syntax errors

File syn.h:

int f(};
conts int i = 7;

Command Prompt:

% cpp2sdl syn.h
Parsing C/C++ input...
Syntax errors found. Cannot perform SDL translation.
#SDTREF(TEXT,syn.h,1,7)
ERROR 3200 Syntax error.
#SDTREF(TEXT,syn.h,2,7)
ERROR 3200 Syntax error.
2 errors and 0 warnings.

CPP2SDL will proceed with semantic analysis only if no errors were found during the syntactic analysis. The semantic analysis that is done by CPP2SDL is not complete according to the C/C++ standards, but only a limited number of semantic tests are performed:

Example 143 : Semantic errors

File sem.h:

template <class U, int d> class S {
public:
U arr[d];
};
typedef unknown T; // T depends on undeclared type
const unknown a = 3;
T f(int, char);
S<T, 3> var;
typedef S<> t1; // Too few actual arguments
typedef S<char, 5, 5> t2; // Too many actual arguments
typedef S<int, int> t3; // Argument type mismatch

Command Prompt:

% cpp2sdl -errorlimit 10 sem.h
Parsing C/C++ input...
Translating C/C++ to SDL...
Generating SDL...
#SDTREF(TEXT,sem.h,11,9)
ERROR 3263 Illegal instantiation of template 'S'.
#SDTREF(TEXT,sem.h,10,9)
ERROR 3263 Illegal instantiation of template 'S'.
#SDTREF(TEXT,sem.h,9,9)
ERROR 3263 Illegal instantiation of template 'S'.
#SDTREF(TEXT,sem.h,8,3)
ERROR 3261 The type 'T' is undeclared, or is depending on an undeclared type.
#SDTREF(TEXT,sem.h,7,3)
ERROR 3261 The type 'T' is undeclared, or is depending on an undeclared type.
#SDTREF(TEXT,sem.h,6,15)
ERROR 3261 The type 'unknown' is undeclared, or is depending on an undeclared type.
#SDTREF(TEXT,sem.h,5,17)
ERROR 3261 The type 'unknown' is undeclared, or is depending on an undeclared type.
#SDTREF(TEXT,sem.h,1,33)
WARNING 3211 Cannot translate template declaration. The declaration will be ignored.
7 errors and 1 warnings.

Note that the command line option -errorlimit can be used to set a limit for the number of errors to report before terminating a translation.

1

One example of such a type dependency is when the source type of a typedef type is undeclared. Usages of the typedef type will then be considered to be undeclared.


http://www.ibm.com/rational
Contents Index Previous Next