Forward declaration issue (error: previous declaration of 'tst' was here)
Hani Ayoub
hani.ayoub@live.com
Tue Dec 2 15:31:00 GMT 2008
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.
The same code compiles fine with Metaware compiler...
Rob Quill wrote:
>
> 2008/11/30 Hani Ayoub <hani.ayoub@live.com>:
>>
>> If I do so, I'll have to write "struct _tst" instead of "tst" when I use
>> the
>> struct...
>
> Can you explain a bit more about what you are trying to do, because
> the following compiles fine for me:
>
>>>> 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; };
>>> ...
>
> when compiling with "gcc tst.c"
>
> That is with gcc 4.2.4, not that I think it should make a difference.
>
> Rob
> - Hide quoted text -
>
>>>> when compiling: "gcc tst.c tst2.h tst.h" I get the following errors:
>>> ...
>>>> The problem is that "tst" is redefined... but I cannot change "tst.h"
>>>> file...
>>>
>>> So, what about:
>>>
>>> * Removing the typedef from tst2.h -- "tst" is already typedefed in
>>> tst.h.
>>>
>>> * Compiling tst.c only, not the headers.
>>>
>>> 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-tp20755376p20757930.html
>> Sent from the gcc - Help mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Forward-declaration-issue-%28error%3A-previous-declaration-of-%27tst%27-was-here%29-tp20755376p20794187.html
Sent from the gcc - Help mailing list archive at Nabble.com.
More information about the Gcc-help
mailing list