Kenneth Brody wrote:[color=blue]
> Is there any way to know if there is a typedef of a given name?[/color]
Not directly, no.
[color=blue]
> Specifically, I need to know if the compiler has a 64-bit integer type,
> and need to know if "int64_t" exists. Something like this pseudo-code:
>
> #if typedef(int64_t)
> typedef int64_t MY_BIG_INT
> #elif typedef(long long)
> typedef long long MY_BIG_INT
> #else
> typedef long MY_BIG_INT
> #endif
>
> (Yes, this program needs to work on systems which don't have a 64-bit
> integers, and it needs to take advantage of them if they are there.)[/color]
`#if __STDC_VERSION__ >= 199901L' means "C99 or later"
and implies the existence of the <stdint.h> header. Having
included this header, you can then check for the presence
of macros like INT64_MAX or UINT_LEAST64_MAX (depending on
whether you want signed or unsigned, exactly or at least 64
bits).
If you don't have C99, you still might be lucky: Some C90
implementations provide a 64-bit `long'. You can check by
including <limits.h> and inspecting the values of LONG_MAX
and/or ULONG_MAX (with care; see below).
Finally, some pre-C99 implementations provide `long long'
if invoked in a non-conforming mode. If yours does so and if
it supports `long long' in the C99 style, <limits.h> will
define LLONG_MAX and ULLONG_MAX for you to check.
Putting it all together, you'd get something like this
(the indirect value tests cater to C90 preprocessors, which
might not be able to parse longer-than-`long' numbers):
#if __STDC_VERSION__ >= 199901L
#include <stdint.h>
#ifdef INT_LEAST64_MAX
typedef int_least64_t MyBigInt;
#define MYBIGBITS 64
#endif
#endif
#ifndef MYBIGBITS
#include <limits.h>
#if (LONG_MAX >> 31) >> 31 >= 1
typedef long MyBigInt;
#define MYBIGBITS 64
#elif (LLONG_MAX >> 31) >> 31 >= 1
/* non-conforming but helpful C90 */
typedef long long MyBigInt;
#define MYBIGBITS 64
#else
/* oh, well -- better luck next time */
typedef long MyBigInt;
#define MYBIGBITS 32
#endif
#endif
[color=blue]
> Also, what is the standard include file which would be needed to have
> the int64_t typedef included? I see it in <stdint.h> on one compiler
> I have, and <native.h> on another. I don't see these headers being
> included by other standard headers on these systems.[/color]
C99 specifies <stdint.h> but not <native.h>. C90 specifies
neither, so don't try to #include it until you've established
that you've got a C99 implementation.
--
Eric.Sosman@sun.com