Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - if the compiler prints diagnostic messages to the screen, it will also place http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
If the compiler prints diagnostic messages to the screen, it will also place
a copy of these messages in a file in your current directory.  The file will
have the same file name as the source file and an extension of ".err".  The
compiler issues two types of diagnostic messages, namely warnings or errors.
 A warning message does not prevent the production of an object file.
 However, error messages indicate that a problem is severe enough that it
must be corrected before the compiler will produce an object file.  The
error file is a handy reference when you wish to correct the errors in the
source file.

Just to illustrate the diagnostic features of Watcom C/C++, we will modify
the "hello" program in such a way as to introduce some errors.

Example:

     #include <stdio.h>

     int main()
       {
          int x;
          printf( "Hello world\n" );
          return( y );
       }

The equivalent C++ program follows:

Example:

     #include <iostream.h>
     #include <iomanip.h>

     int main()
     {
         int x;
         cout << "Hello world" << endl;
         return( y );
     }

In this example, we have added the lines:


     int x;

and


     return( y );

and changed the keyword void to int.

We compile the program with the "warning" option.

Example:

     C>compiler_name hello /w3

For the C program, the following output appears on the screen.


     hello.c(7): Error! E1011: Symbol 'y' has not been declared
     hello.c(5): Warning! W202: Symbol 'x' has been defined, but not
                                referenced
     hello.c: 8 lines, included 174, 1 warnings, 1 errors

For the C++ program, the following output appears on the screen.


     hello.cpp(8): Error! E029: (col 13) symbol 'y' has not been declared
     hello.cpp(9): Warning! W014: (col 1) no reference to symbol 'x'
     hello.cpp(9): Note! N392: (col 1) 'int x' in 'int main( void )'
                   defined in: hello.cpp(6) (col 9)
     hello.cpp: 9 lines, included 1628, 1 warning, 1 error

Here we see an example of both types of messages.  An error and a warning
message have been issued.  As indicated by the error message, we require a
declarative statement for the identifier y.  The warning message indicates
that, while it is not a violation of the rules of C/C++ to define a variable
without ever using it, we probably did not intend to do so.  Upon examining
the program, we find that:

 1. the variable x should have been assigned a value, and

 2. the variable y has probably been incorrectly typed and should have been
    entered as x.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson