Hi Richard,

> -----Original Message-----
> From: Richard A. O'Keefe [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 24, 2002 1:20 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: spurious redefinition warnings on Windows NT
>
>
> Martin Roehrig <[EMAIL PROTECTED]> wrote:
>
>       ---------------- myheader.h --------------
>       typedef int mytype;
>       ------------------------------------------
>
>       ---------------- mycode_1.c --------------
>       #include "myheader.h"
>       ------------------------------------------
>
>       ---------------- mycode_2.c --------------
>       #include "MYHEADER.H"
>       ------------------------------------------
>
>       > splint *.c
>       Splint 3.0.1.6 --- 11 Feb 2002
>
>       MYHEADER.H(1,13): Datatype mytype defined more than once
>         A function or variable is redefined. One of the declarations should use
>         extern. (Use -redef to inhibit warning)
>          myheader.h(1,13): Previous definition of mytype
>
> The wording of this message needs improving, as putting 'extern' into
> a 'typedef' is quite illegal.
>
> My preferred method for handling the duplicate inclusion problem is
>
>       ---------------- myheader.h ----------------
>       #ifndef MYHEADER_H_
>       #define MYHEADER_H_ 20020422 /* or whatever the date is */
>       ... usual contents ...
>       #endif/*MYHEADER_H_*/

Right, but that was not the problem. As you see in the code the header is just 
included once by each of the .c files.
The problem is that splint mingles the two includes although they never come together 
in the same *compilation* unit.
However it cannot but do so as it would miss some errors otherwise:

--------------- header1.h -------------
typedef int mytype;
---------------------------------------

--------------- header2.h -------------
typedef double mytype;
---------------------------------------

--------------- code1.c ---------------
#include "header1.h"
extern mytype myvar;
---------------------------------------

--------------- code2.c ---------------
#include "header2.h"
mytype myvar;
---------------------------------------

It's almost the same situation: the two includes don't meet in the same compilation 
unit, but of course all sorts of trouble would
arise if the object codes from code1.c and code2.c were *linked* together. Therefore 
splint has to consider both header files if it
is called with both code files (assuming that such a call means all .c files are 
eventually linked together, which is a reasonable
for a lint tool).
I admit it's not exactly the same situation, as here you have two different headers 
with possibly different definitions, whereas
above there seemed to be two different headers although you had only one header 
because of the file system limitations.

[...]
> Note that using the same file name with different case patterns is
> a _great_ recipe for porting problems.

You are completely right.

  Perhaps splint should warn
> if that happens
>     Warning: file may be included under two different names:
>       <lino1> myheader.h
>       <lino2> MYHEADER.H

Nice idea. David, what about that as one aspect of the flag you proposed for the next 
release?
Of course it makes only sense on a file system that really doesn't make a difference 
between lower case and upper case letters.

Greetings
Martin


Reply via email to