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

Bug#159804: printf("%#Xll",x) can be funny



Package: gcc
Version: 2.95.4-16
Severity: normal

This could be glibc error.  Following program did not act as I expected.

/*
 * type cast/formatting bug check for GCC / GLIBC
 * (C) Osamu Aoki, Mon Sep  2 17:51:30 UTC 2002
 */
#include <stdio.h>

int
main(int argc, char *argv)
{
	unsigned int b;
	unsigned long long int d; /* itry also unsigned long int  */
	b = 0xff;
	d = b;
	printf("Good %%X %%X %X %X\n", b, d);
	printf("Oops %%llX %%llX %llX %llX\n", b, d);
	printf("Oops %%llu %%llu %lli %llu\n", b, d);
	printf("Oops %%llX %%llX %llX %llX if casted to (unsigned int)\n", (unsigned int) b, (unsigned int) d);
	printf("Oops %%llX %%llX %llX %llX if casted to (unsigned long int)\n", (unsigned long int) b, (unsigned long int) d);
	printf("Oops %%lX %%lX %lX %lX if casted to (unsigned long long int)\n", (unsigned long long int) b, (unsigned long long int) d);
	printf("Good %%llX %%llX %llX %llX if casted to (unsigned long long int)\n", (unsigned long long int) b, (unsigned long long int) d);
	return(0);
};

---- 

Good %X %X FF FF
Oops %llX %llX FF000000FF 80497CC00000000
Oops %llu %llu 1095216660735 577753554639388672
Oops %llX %llX FF000000FF 80497CC00000000 if casted to (unsigned int)
Oops %llX %llX FF000000FF 80497CC00000000 if casted to (unsigned long int)
Oops %lX %lX FF 0 if casted to (unsigned long long int)
Good %llX %llX FF FF if casted to (unsigned long long int)

This is not what I expected.

(Please laugh at me if this is a FAQ of type conversion in C.)

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  libc6          2.2.5-11.1     GNU C Library: Shared libraries and Timezone
ii  libc6-dev      2.2.5-11.1     GNU C Library: Development Libraries and Hea
ii  gcc            2.95.4-16      The GNU C compiler.
-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  Osamu Aoki <debian@aokiconsulting.com> @ Cupertino, CA USA         +




Reply to: