Mail Archives: djgpp/1997/01/15/13:13:20
x DOT pons AT cc DOT uab DOT es <ILGES AT cc DOT uab DOT es> wrote:
: Dear programmers,
: If I write something like this in a xxx.h file
: typedef unsigned char BYTE;
: and I have *THE SAME* typedef in some other yyy.h file,
: both included in the same .c file, the DJGPP compiler complains
: that:
: file xxx.h line n redefinition of `BYTE'
: file yyy.h line m `BYTE' previously declared here
: Is there some way to avoid this error, which is not even a warning
: in other compilers (provided, of course, that both definitions are
: identical)?
Actually, I think this is correct in ANSI, maybe other compilers have
`softened' the definition a bit (which causes highly unportable
programs, of course).
Usually, you work around this like this:
Put all your typedefs in a single .h file that is included in any file
that needs the types and `shield' it again multiple inclusion,
something like this:
type_byte.h:
#ifndef TYPE_BYTE_H
#define TYPE_BYTE_H
typedef ...
#endif
gcc's cpp will even figure out that the file was already included and
ignore the next include (so it will not take up compilation time).
Or you could use single defines for each type, something like
#ifndef TYPE_BYTE_DEFINED
#define TYPE_BYTE_DEFINED
typedef ...
#endif
in each source file, but I would prefer the 1st solution.
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (MIME, NeXT) | nobody knows
lehmann AT mathematik DOT th-darmstadt DOT de (MIME) | you're a dog."
<URL:http://home.pages.de/~lehmann/>
- Raw text -