Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug427.cpp

1     #include <stdio.h>
2
3     // Error macro
4     #define error(text)     \
5         // show line number first \
6         fprintf( stderr, "Error(%d):", __LINE__ ),\
7         fprintf( stderr, "%s\n", text )
8
9     int main( int argc, const char * const *argv )
10        {
11        int options = 0;
12        // check some args are supplied.
13        if( argc < 2 ) { error( "args" ); return 1; }
14        for( int i = 1; i < argc; i++ )
15            if( *argv[i] == '-' ) options++;
16        printf( "%d option(s) were supplied to this program\n", options );
17        return 0;
18        }

The programmer expected his program to produce an error message if no command line arguments were supplied. Instead he received no output. How come? (thanks to Martyn Honeyford of IBM UK Labs).


bug427.cpp lint Output

-- Module:   bug427.cpp
                              _
    // show line number first \
bug427.cpp(5) : Warning 427: // comment terminates in \
                                              _
    fprintf( stderr, "Error(%d):", __LINE__ ),\
bug427.cpp(6) : Warning 427: // comment terminates in \

Reference Manual Explanation

 
427   // comment terminates in \  -- A one-line comment terminates in the back-slash 
      escape sequence.  This means that the next line will be absorbed in the comment (by 
      a standards-conforming compiler -- not all compilers do the absorption, so beware).  
      It is much safer to end the line with something other than a back-slash.  Simply 
      tacking on a period will do.  If you really intend the next line to be a comment, 
      the line should be started with its own double slash (//).

If you have comments or questions about this bug, please post them to our   Discussion Forum

Previous Bug - Bug #524 - January 2004

[ new ] Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2006, Gimpel Software, All rights reserved.