Compiler bug
Ed Gould
ed at mtxinu.UUCP
Wed May 8 02:15:49 AEST 1985
> I noticed this idiosyncrasy with regards to our C compiler. Given the
> following
>
> > int a;
> > int a;
> >
> > main()
> > {
> > for (;;)
> > ;
> > }
>
> When compiling this, the compiler generates no error messages. Seems
> to me, it should give a "redeclaration of a" error message. It does
> give the error message, if the two int's are made automatic variables
> (i.e., declared within main()).
>
> ... running 4.2BSD.
The C language allows multiple definitions of *external* variables.
In all (that I know of, anyway) implementations under Unix declarations
made outside of a function are external - not just to the functions
in that file, but to the file as well.
Some AT&T compilers - specifically those on System V - complain about
the construction you describe. Lots of folks have griped about that!
If the declarations *within* one file aren't consistent, e.g.,
int a;
struct {
int c;
int d;
} a;
any compiler should complain. (Of course, there is *no* checking
if the declarations are in separately-compiled files!)
--
Ed Gould mt Xinu, 2910 Seventh St., Berkeley, CA 94710 USA
{ucbvax,decvax}!mtxinu!ed +1 415 644 0146
More information about the Comp.unix
mailing list