[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Patch: Permit certain pointer assignments (grischka-2

From: David A. Wheeler
Subject: Re: [Tinycc-devel] Patch: Permit certain pointer assignments (grischka-2005-09-25 case_7)
Date: Fri, 04 May 2007 09:12:01 -0400 (EDT)

David A. Wheeler wrote:
> > In practice, given:
> >     struct _s1 { int a, b, c; } *p1 = NULL;
> > gcc will accept the following assignment without even a warning:
> >     struct _s2 { int a, b, c; } *p2 = p1;
> > (Notice that the struct tags are different, but no warning is given.)

Dave Dodge: 
> In the same translation unit?  Even old gcc 3.3.3 with no options complains:
>   warning: initialization from incompatible pointer type
> It's a constraint violation, so the Standard requires a diagnostic for
> it if it's visible to the compiler.

Yes, in the same translation unit.  I used gcc 4.1.1, no options, and it did 
NOT complain.

The C99 spec clearly says that they have to have the same name if they're in 
DIFFERENT translation units.. but it's not instantly obvious if there's a 
problem when they're in the SAME translation unit.

> Aside: it's actually pretty important that the compiler complain about
> this sort of thing.  Some applications use struct encapsulation
> entirely to get extra type-checking for basic types.

Okay; the patch I posted always warns (complains), unless the structures have 
the same name (which is what you're SUPPOSED to do). So that's consistent.

--- David A. Wheeler

reply via email to

[Prev in Thread] Current Thread [Next in Thread]