look at the program at the end: g++ will accept it, but gcc
will refuse it
alrm.c:5: redefinition of `TOTO'
alrm.c:4: `TOTO' previously declared here
it seems redefinitions are ok with C++ as long as the typedef
is the same. How can I get gcc to accept that too?
I use gcc and g++ 2.95.
-----------------------------------
#include <stdio.h>
#include <stdlib.h>
typedef int TOTO;
typedef int TOTO;
int main(int argc,char *argv[])
{
TOTO u;
return 0;
}
-----------------------------------
--
Emmanuel Michon
--
comp.lang.c.moderated - moderation address: cl...@plethora.net
> look at the program at the end: g++ will accept it, but gcc
> will refuse it
It's not legal in C. I don't know about C++.
> typedef int TOTO;
> typedef int TOTO;
You won't be able to get a C compiler to accept this without
diagnostics since it is invalid C.
[snippage]
I don't know if GCC has a special kludge for this, but the usual
(portable) solution (used in header files, of course) is
#ifndef TOTO_DEFINED // idempotency lock
typedef int TOTO;
#define TOTO_DEFINED
#endif
> Hi,
>
> look at the program at the end: g++ will accept it, but gcc
> will refuse it
>
> alrm.c:5: redefinition of `TOTO'
> alrm.c:4: `TOTO' previously declared here
>
> it seems redefinitions are ok with C++ as long as the typedef
> is the same. How can I get gcc to accept that too?
>
> I use gcc and g++ 2.95.
>
> -----------------------------------
> #include <stdio.h>
> #include <stdlib.h>
>
> typedef int TOTO;
> typedef int TOTO;
>
> int main(int argc,char *argv[])
> {
> TOTO u;
>
> return 0;
> }
> -----------------------------------
>
> --
> Emmanuel Michon
It is just plain flat-out illegal in C to redefine a typedef, even if
the redefinition is identical. So the C language answer is: there is
no way. If you are looking for a compiler specific solution, ask in a
gcc newsgroup like news:gnu.gcc.help.
Jack Klein
--
Home: http://jackklein.home.att.net
> alrm.c:5: redefinition of `TOTO'
> alrm.c:4: `TOTO' previously declared here
>
> it seems redefinitions are ok with C++ as long as the typedef
> is the same. How can I get gcc to accept that too?
It is an error, not a warning. I don't think you can disable it.
And it shouldn't happen, should it?
--
Oleg Goldshmidt | BLOOMBERG L.P. (BFM) | ol...@bfr.co.il
"... We work by wit, and not by witchcraft;
And wit depends on dilatory time." - W. Shakespeare.