bytebro wrote:
Is there any way of testing at compile time (i.e. by the preprocessor)
whether a particular type has been declared?
Not directly, no, because types don't come into existence
until after the preprocessor has finished. Keywords like `int'
and `typedef' are merely source tokens to the preprocessor; they
aren't even recognized as keywords until later in compilation.
I guess what I'm looking for is something like
#if defined(uint8_t)
...
#endif
although of course I know that particular construction doesn't work.
What is usually done is to #define a preprocessor macro in
the same header that declares the type(s) of interest:
typedef unsigned char uint8_t;
#define UINT8_T_DEFINED
.... and then you can test for the macro
#ifdef UINT8_T_DEFINED
Note that `uint8_t' is one of the types from <stdint.hin
C99-conforming implementations. If you are using <stdint.h(as
opposed to writing pre-C99 "free-hand" declarations of your own),
then the macro `UINT8_MAX' is defined if `uint8_t' exists.
I've also tried
#if sizeof(uint8_t) == 1
but that doesn't work either
Since types themselves don't exist during preprocessing, the
sizes of types also don't exist. (In fact, `sizeof' is not even
recognized as an operator this early in the game.)
--
Eric Sosman
es*****@acm-dot-org.invalid