Re: determine base type of a typedef

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

 




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;
}




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

  Powered by Linux