This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Forward declaration issue (error: previous declaration of 'tst' was here)
- From: Hani Ayoub <hani dot ayoub at live dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 4 Dec 2008 07:24:35 -0800 (PST)
- Subject: Re: Forward declaration issue (error: previous declaration of 'tst' was here)
- References: <20755376.post@talk.nabble.com> <20081130110715.GA3206@radix50.net> <20757930.post@talk.nabble.com> <baf6008d0811300626p2e345a68i76fccff87980fe6c@mail.gmail.com> <20794187.post@talk.nabble.com> <20081204134255.GA5264@radix50.net>
I see...
Anyway... I've tried to compile the same code on g++ (instead of gcc), and I
got no error :)
Don't really know why... but works fine...
Baurzhan Ismagulov wrote:
>
> On Tue, Dec 02, 2008 at 07:30:02AM -0800, Hani Ayoub wrote:
>> >>>> tst.h
>> >>>> =======
>> >>>> typedef struct _tst{
>> >>> ...
>> >>>> } tst;
>> >>>
>> >>>> tst2.h
>> >>>> =======
>> >>>> #include "tst.h"
>> >>>>
>> >>>> int foo(tst t);
>> >>>
>> >>>> tst.c
>> >>>> =======
>> >>>> #include <stdio.h>
>> >>>> #include "tst2.h"
>> >>>>
>> >>>> int foo(tst t){ return 1; };
> ...
>> What I'm trying to do is "forward declaration"; means to hide tst struct
>> definition from source or header files that includes tst2.h file.
>
> Then you'll want to remove #include "tst.h" from tst2.h -- struct _tst
> is exactly what you want to hide from tst2.h and tst.c -- and make
> typedef struct _tst tst available somewhere.
>
> I personally would put typedef struct _tst tst in tst.h and hide struct
> _tst declaration within something like #ifdef INTERNAL_TST ... #endif:
>
> tst.h
> =====
> #ifdef INTERNAL_TST
> struct _tst {
> ...
> };
> #endif
>
> typedef struct _tst tst;
>
> user.h
> ======
> #include "tst.h"
> int foo(tst t);
>
> user.c
> ======
> #include "user.h"
> int foo(tst t){ return 1; }
>
> This would provide the same header for both API-providing and API-using
> modules.
>
> With kind regards,
> --
> Baurzhan Ismagulov
> http://www.kz-easy.com/
>
>
--
View this message in context: http://www.nabble.com/Forward-declaration-issue-%28error%3A-previous-declaration-of-%27tst%27-was-here%29-tp20755376p20835653.html
Sent from the gcc - Help mailing list archive at Nabble.com.