[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: Dave Dodge
Subject: Re: [Tinycc-devel] Patch: Permit certain pointer assignments (grischka-2005-09-25 case_7)
Date: Fri, 4 May 2007 08:49:28 -0400
User-agent: Mutt/1.5.12-2006-07-14

On Fri, May 04, 2007 at 09:12:01AM -0400, David A. Wheeler wrote:
> Dave Dodge: 
> > In the same translation unit?
> Yes, in the same translation unit.  I used gcc 4.1.1, no options,
> and it did NOT complain.

Strange; I still get the warning in 4.1.1.  Here's what I'm compiling
(I put it in a function because a file-scope non-constant initializer
causes an error):

  void foo(void)
  struct _s1 { int a, b, c; } *p1 = 0;
  struct _s2 { int a, b, c; } *p2 = p1;

> 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.

Best I can tell from 6.2.7p1 and, no two structure types are
ever compatible within the same translation unit.  The compatibility
between translation units appears to be a special case.

Example 2 in 6.7.7 also mentions this situation:

       After the declarations

               typedef struct s1 { int x; } t1, *tp1;
               typedef struct s2 { int x; } t2, *tp2;

       type t1 and the type pointed to by tp1 are compatible.  Type t1
       is also compatible with type struct s1, but not compatible with
       the types struct s2, t2, the type pointed to by tp2, or int.

                                                  -Dave Dodge

reply via email to

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