This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 4.5.0 Reports invalid warning


On Thu, Jul 15, 2010 at 5:32 PM, Dave Korn <dave.korn.cygwin@gmail.com> wrote:
> On 16/07/2010 00:59, J Decker wrote:
>
>> ------------------------------
>>
>> #define PointerA struct a *
>>
>> void f( PointerA );
>>
>> typedef struct a * PA;
>> struct a { int x; };
>>
>> void f( PA a )
>> {
>> }
>>
>> ---------------------------------
>>
>> This is the output
>>
>> ?warning: 'struct a' declared inside parameter list
>> ?warning: its scope is only this definition or declaration, which is
>> probably not what you want
>> error: conflicting types for 'f'
>> ?note: previous declaration of 'f' was here
>>
>>
>> --------------------------------
>>
>> This is valid C code by every other compiler.
>
> ?Not so, as far as I can tell. ?Comeau online says:
>
>> Comeau C/C++ 4.3.10.1 (Oct ?6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
>> Copyright 1988-2008 Comeau Computing. ?All rights reserved.
>> MODE:strict errors C99
>>
>> "ComeauTest.c", line 3: warning: declaration is not visible outside of function
>> ? void f( PointerA );
>> ? ? ? ? ? ^
>>
>> "ComeauTest.c", line 8: error: declaration is incompatible with "void f(struct a *)"
>> ? ? ? ? ? (declared at line 3)
>> ? void f( PA a )
>> ? ? ? ?^
>>
>> 1 error detected in the compilation of "ComeauTest.c".
>
> ?As long as "struct a" hasn't been (forward-)declared at the time the
> declaration of f() is found, it is a different one from the "struct a" in the
> global namespace that the formal parameter on the definition of f() then
> subsequently refers to.
>

Okay so if I just move the typedef up... (which isn't exactly feasible
in the actual project)


>>
>> #define PointerA struct a *
>>
>> typedef struct a * PA;
>> void f( PointerA );
>>
>> struct a { int x; };
>>
>> void f( PA a )
>> {
>> }

Now it's happy, why can't it just define 'struct a' as an appropriate
name as it used to, the strucutre still isn't defined.

(okay every other compiler I mention is MSVC, OpenWatcom, lcc, and gcc
before now)

> ? ?cheers,
> ? ? ?DaveK
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]