Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 155998

Summary: printf does the wrong thing when given a 64-bit long
Product: Gentoo Linux Reporter: David Geib <dgeib>
Component: [OLD] Core systemAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED INVALID    
Severity: normal    
Priority: High    
Version: 2006.1   
Hardware: AMD64   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description David Geib 2006-11-22 22:30:17 UTC
david@localhost ~ $ cat test64.c
#include<stdio.h>

int main()
{
        long i = 0x0123456789abcdef;
        printf("%d bit long: %x\n", 8*sizeof(i), i);
}
david@localhost ~ $ gcc test64.c -o test64
david@localhost ~ $ ./test64
64 bit long: 89abcdef
Comment 1 SpanKY gentoo-dev 2006-11-26 07:16:53 UTC
has nothing to do with coreutils afaict
Comment 2 SpanKY gentoo-dev 2006-11-26 07:19:31 UTC
you should really build with warnings enabled (-Wall)

then you should read the printf(3) manpage

%x takes an unsigned int and since you did not include any length modifiers, printf() only shows (unsigned int)(0x0123456789abcdef) which correctly evaluates to 0x89abcdef