Stupid question about integer sizes

Borja Marcos borjam at sarenet.es
Tue Feb 19 13:20:55 UTC 2013


Hello,

I'm really sorry if this is a stupid question, but as far as I know, u_int64_t defined in /usr/include/sys/types.h should *always* be
a 64 bit unsigned integer, right? 

Seems there's a bug (or I need more and stronger coffee). Compiling a program on a 64 bit system with -m32 gets the 64 bit integer types wrong.

% cat tachin.c 
#include <sys/types.h>
#include <stdio.h>


main()
{
	printf("sizeof uint64_t = %d\n", sizeof(uint64_t));
	printf("sizeof u_int64_t = %d\n", sizeof(u_int64_t));
}



uname -a
FreeBSD splunk 9.1-RELEASE FreeBSD 9.1-RELEASE #14: Wed Jan 23 17:24:05 CET 2013     root at splunk:/usr/obj/usr/src/sys/SPLUNK  amd64

% gcc -o tachin tachin.c
% ./tachin
sizeof uint64_t = 8
sizeof u_int64_t = 8

% ./tachin
sizeof uint64_t = 4                       <======= WRONG!!
sizeof u_int64_t = 4                    <======= WRONG!!

The same happens with clang.

% clang -m32 -o tachin tachin.c
tachin.c:5:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^~~~
1 warning generated.
% ./tachin
sizeof uint64_t = 4			<======= WRONG!!
sizeof u_int64_t = 4			<======= WRONG!!


if I do the same on a i386 system (8.2-RELEASE, but it should be irrelevant) the u_int64 types have the correct size.

%gcc -o tachin tachin.c
%./tachin
sizeof uint64_t = 8
sizeof u_int64_t = 8





Am I missing anything? Seems like a too stupid problem to be a real bug. Sorry if I am wrong.






Borja.



More information about the freebsd-hackers mailing list