Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

making gcc eat a typedef redefinition

3,170 views
Skip to first unread message

Emmanuel Michon

unread,
Mar 21, 2000, 3:00:00 AM3/21/00
to
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
--
comp.lang.c.moderated - moderation address: cl...@plethora.net

Ben Pfaff

unread,
Mar 22, 2000, 3:00:00 AM3/22/00
to
Emmanuel Michon <emmanue...@sdesigns.com> writes:

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

Douglas A. Gwyn

unread,
Mar 22, 2000, 3:00:00 AM3/22/00
to
Emmanuel Michon wrote:
> ... How can I get gcc to accept that too?

> typedef int TOTO;
> typedef int TOTO;

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

Jack Klein

unread,
Mar 22, 2000, 3:00:00 AM3/22/00
to
On Tue, 21 Mar 2000 19:39:50 GMT, Emmanuel Michon
<emmanue...@sdesigns.com> wrote in comp.lang.c.moderated:

> 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

Oleg Goldshmidt

unread,
Mar 22, 2000, 3:00:00 AM3/22/00
to
Emmanuel Michon <emmanue...@sdesigns.com> writes:

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

0 new messages