autoconf
[Top][All Lists]
Advanced

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

Re: determine base type of a typedef


From: Russell Shaw
Subject: Re: determine base type of a typedef
Date: Fri, 23 Oct 2020 12:09:46 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1


On 23/10/20 9:23 am, Anatoli wrote:
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".
You could use an AC_COMPILE thing to run a small bit of C that does something 
like:

int
test(int argc, char **argv)
{
    time_t t = -1;

    if(t < 0) {
        if(sizeof(time_t) == sizeof(int)) {
            printf("d");
        }
        else if(sizeof(time_t) == sizeof(long int)) {
            printf("ld");
        }
        else if(sizeof(time_t) == sizeof(long long int)) {
            printf("lld");
        }
        else {
            printf("error");
        }
    }
    else {
        if(sizeof(time_t) == sizeof(int)) {
            printf("u");
        }
        else if(sizeof(time_t) == sizeof(long int)) {
            printf("lu");
        }
        else if(sizeof(time_t) == sizeof(long long int)) {
            printf("llu");
        }
        else {
            printf("error");
        }
    }

    return 0;
}



reply via email to

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