autoconf
[Top][All Lists]
Advanced

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

determine base type of a typedef


From: Anatoli
Subject: determine base type of a typedef
Date: Thu, 22 Oct 2020 19:23:04 -0300

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]