determine base type of a typedef

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,

Is there a way to determine with autoconf what's the base type of a typedef?

I'm trying to accomplish the following:

There are standard types time_t, off_t, size_t and similar that are defined differently on different platforms/OS.

For example, time_t is defined as "long int" on Linux amd64, but as "long long int" on OpenBSD amd64. So when printing a time_t var with printf & co, on Linux it's OK to use "%ld" format specifier, but on OpenBSD it should be "%lld".

For GNU C this is "the same" as both are of 8 bytes, but clang generates a warning like: "warning: format specifies type 'long' but the argument has type 'time_t' (aka 'long long')".


I was trying to determine with autoconf the final base type of the time_t typedef, so I could specify in configure.ac something like:

#define TIME_T_FMT "%lld"

and use it later in printf(), but all I could find was either the size of a type (e.g. SIZEOF_TIME_T, but it's always 8) or whether the type is defined (the AC_TYPE_XXX and AC_CHECK_TYPE(S) which are either true or false), but I can't find a macro or some other way to get the base type of a typedef, i.e. for the result of a macro to be e.g. "long long int" so I could compare it sort of like this:

#if (AC_TYPE(time_t) == "long long int")
#define TIME_T_FMT "%lld"
#elif (AC_TYPE(time_t) == "long int")
#define TIME_T_FMT "%ld"
#else
#error dont know what to use for TIME_T_FMT
#endif


Maybe there's another way to accomplish the same?

Thanks,
Anatoli




[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux