NCEP CCS Conversion Guide
Issues Converting FORTRAN and C/C++ Programs
Back to Main Page
Topic: Size of long and long int variables in C
Posted by: Stephen Gilbert
Updated by
Post Date: 12/06/2002
Last Updated: 
Problem: 

The size of "C" variables long and long int, are different on snow/frost depending on how the program is compiled.
If the program is compiled using 32-bit addressing ( -q32 compiler option ), then variables declared as long or
long int are stored as four byte values.  However, if compiling with 64-bit addressing (-q64), these variables
would now be stored in 8 bytes. 

Solution:  

Example:

Consider the following program:

#include <stdio.h>
int main(void)
{
  printf("size of int = %d\n",sizeof(int));
  printf("size of long = %d\n",sizeof(long));
  printf("size of long int = %d\n",sizeof(long int));
  printf("size of long long = %d\n",sizeof(long long));

When this program is compiled with 32-bit addressing (-q32), the ouput is:

size of int = 4
size of long = 4
size of long int = 4
size of long long = 8

However, if compiled with -q64, we get:

size of int = 4
size of long = 8
size of long int = 8
size of long long = 8
 
 

Back to Main Page