Kevin Smith wrote:
[Re: Which preprecessor directive will detect if a typedef exists yet?
Eg #if IS_TYPE(sometype_t)?]
Thanks.
Please don't rely upon the subject line to convey your question. It's
quite common for people to read the body of a message without even
looking at the subject line. Put the question itself in your post,
though it's OK to put a summary of the question in the subject line.
To answer your question, C provides no mechanism whereby your code can
test for the presence of a typedef. Even if C did provide one, it could
not be available for use in a #if: preprocessor directives are handled
during translation phase 4; typedefs don't get interpreted until
translation phase 7. If any method for doing this were added to C, it
would have to rely upon a phase 7 construct, perhaps
if(is_typedef(sometype_t)).
However, the main thing you would want to do with something like
is_typedef() is to control how the specified identifier is used in your
code. Unfortunately, both branches of the if statement would have to use
that identifier in a fashion that is legal, whether or not it is a
typedef, which defeats the only purpose it could reasonably serve.
It might be possible to get around this problem by splitting translation
phase 7 into 2 or more phases, but I've given the idea just enough
thought to realize that it would be horrendously difficult to do so.