Survey of sizes of types
Jens Schweikhardt
schweikh@schweikhardt.net
Fri Jan 2 13:18:00 GMT 2009
hello, world\n
I am investigating what sizes of types GCC is using on various
implementations (native or cross compiler). If you want to help out,
please run the follwoing shell script. I promise it is not a virus and
it is spamming only my own email inbox :-)
I am especially interested in the non-i386 architectures and cross
compilers, e.g. amd64, sparc, mips, arm, powerpc, ... I'll summarize all
answers and post a summary here for you to enjoy. Thanks!
Regards,
Jens
#!/bin/sh
#
# usage: mailsz [gccname]
# example: mailsz # Will use "gcc"
# example: mailsz powerpc-linux-gcc
GCC=${1:-gcc} # your gcc binary name, eg. powerpc-linux-gcc or whatever.
# Set this to your own address if you want to see what you'll send.
RECIPIENT=schweikh@schweikhardt.net
cat << "EOF" > sizes.c
#include <stdio.h>
#include <wchar.h>
#define STR(x) #x
#define STREXP(x) STR(x)
static char
sb[__CHAR_BIT__] = "",
sc[sizeof(char)] = "",
ss[sizeof(short)] = "",
si[sizeof(int)] = "",
sl[sizeof(long)] = "",
sll[sizeof(long long)] = "",
sw[sizeof(wchar_t)] = "",
sf[sizeof(float)] = "",
sd[sizeof(double)] = "",
sld[sizeof(long double)] = "",
sp[sizeof(void *)] = "";
int main (void)
{
puts ("b " STREXP(__CHAR_BIT__));
printf ("c %zd\n", sizeof sc);
printf ("s %zd\n", sizeof ss);
printf ("i %zd\n", sizeof si);
printf ("l %zd\n", sizeof sl);
printf ("ll %zd\n", sizeof sll);
printf ("w %zd\n", sizeof sw);
printf ("f %zd\n", sizeof sf);
printf ("d %zd\n", sizeof sd);
printf ("ld %zd\n", sizeof sld);
printf ("p %zd\n", sizeof sp);
return 0;
}
EOF
(
$GCC -v -E -dM -x c /dev/null 2>&1
# Create assembler input.
$GCC -S sizes.c
cat sizes.s
# Create executable.
$GCC -o sizes sizes.c
./sizes 2>/dev/null # Fails for cross compilers.
) | mailx -s "Sizes for $GCC" $RECIPIENT
# End of script.
More information about the Gcc-help
mailing list