From: Alexander Lehmann Newsgroups: comp.os.msdos.djgpp Subject: Re: Why two identical typedef are considered an error in DJGPP? Date: 15 Jan 1997 00:26:53 GMT Organization: Technische Hochschule Darmstadt Lines: 59 Message-ID: <5bh88d$79r@rs18.hrz.th-darmstadt.de> References: <01IE7MKQWZ2Q003361 AT cc DOT uab DOT es> NNTP-Posting-Host: fb0408.mathematik.th-darmstadt.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp x DOT pons 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."