Go to main content

Oracle® Solaris 64-bit Developer's Guide

Exit Print View

Updated: March 2019
 
 

Please tell us how to improve our documentation:


0 of 500

0 of 500



0 of 500
Thank you for your feedback! If you want to participate in content improvement and share additional information, please click Feedback button.
Rate this document:

4.7 Sample 64-Bit From 32-Bit Program

The following sample program, foo.c, directly illustrates the effect of the LP64 data model in contrast to the ILP32 data models. The same program can be compiled as either a 32-bit program or a 64-bit program.

#include <stdio.h>
int
main(int argc, char *argv[])
{
		(void) printf("char is \t\t%lu bytes\n", sizeof (char));
		(void) printf("short is \t%lu bytes\n", sizeof (short));
		(void) printf("int is \t\t%lu bytes\n", sizeof (int));
		(void) printf("long is \t\t%lu bytes\n", sizeof (long));
		(void) printf("long long is \t\t%lu bytes\n", sizeof (long long));
		(void) printf("pointer is \t%lu bytes\n", sizeof (void *));
		return (0);
} 

The result of 32-bit compilation is:

$ cc -m32 -O -o foo32 foo.c
$ foo32 
char is          1 bytes
short is         2 bytes
int is           4 bytes
long is          4 bytes
long long is     8 bytes
pointer is       4 bytes   

The result of 64-bit compilation is:

$ cc -m64 -O -o foo64 foo.c 
$ foo64
char is          1 bytes
short is         2 bytes
int is           4 bytes
long is          8 bytes
long long is     8 bytes 
pointer is       8 bytes

Note -  The default compilation mode depends on the compiler being used. To determine whether your compiler produces 64-bit or 32-bit code by default, refer to the compiler documentation.