|
|
Stefano Chiappa schrieb:
I'd like to know if there is a way to know if a type already exist in C.
Suppose I have
typedef unsigned char uchar;
and, due to a messy-include dependency, I'd like to know if the type
uchar already exists.
I checked that:
#if defined(uchar)
... something to do if uchar has not already defined ...
#endif
I think that this does not work while typedef is a C keyword and not a
pre-processor command as #if defined( is.
This does not work in C.
Clean up your code in a way that you have only one header containing
a typedef of said type; in combination with header guards, you can
be sure that to have exactly one typedef of uchar, you have to
#include "mytypes.h"
-- independent of whether there were previous typedefs or not.
If there seems to be a good reason to typedef uchar in more than
one header, then isolate the typedef in a header of its own and
include that in all the other headers.
So, if you get a diagnostic from gcc although you did that, then
some outside header provides a typedef for the same identifier, i.e.
you have to fix it.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
|
|