Integer size in C on 32-bit and 64-bit system logo

Integer size in C on 32-bit and 64-bit system

Free

C integer sizes on 32-bit vs 64-bit Linux

FreeFree tier
Type
Open Source

About Integer size in C on 32-bit and 64-bit system

This blog post provides a quick reference table and explanation of the sizes of common C integer types (short int, int, long int, long long int, size_t, void*) on 32-bit and 64-bit Linux systems using GCC on Intel architecture. It includes a sample C program to print the sizes and discusses portable printf formatting with the 'z' length modifier and PRIu32 macros from inttypes.h. The post is aimed at C/C++ developers who need to ensure correct integer size assumptions when writing code that must work on both 32-bit and 64-bit platforms.

Key Features

Clear table comparing integer sizes on 32-bit and 64-bit Linux executables
Sample C code to programmatically verify sizes using sizeof()
Explanation of the 'z' length modifier for size_t in printf
Use of PRIu32 macro from inttypes.h for portable integer printing
Covers short int, int, long int, long long int, size_t, and void*

Pros & Cons

Pros
  • Provides explicit size values for both 32-bit and 64-bit executables in a concise table
  • Includes working C code that readers can compile to verify results themselves
  • Introduces portable printf techniques (z modifier and PRI macros) relevant to cross-platform development
  • Clearly states the platform and compiler assumptions (GCC on Intel Linux)
Cons
  • Only covers GCC on Linux for Intel architecture; does not cover other compilers or architectures like ARM
  • Post is from 2012 and may not address newer C standards or compiler behaviors
  • Does not discuss other integer types such as int8_t, int16_t, int32_t, int64_t explicitly
  • Limited to Intel; results may differ on other CPU families (e.g., ARM)

Best For

C/C++ developers writing cross-platform code for 32-bit and 64-bit LinuxEmbedded systems programmers needing to confirm integer sizes on target architecturesUnderstanding portability issues related to integer type sizes in CLearning how to use inttypes.h macros for format-agnostic printf

FAQ

How big is an int on 32-bit and 64-bit Linux?
According to the post, int is 32 bits (4 bytes) on both 32-bit and 64-bit Linux when using GCC on Intel.
What is the size of long int on 32-bit vs 64-bit?
long int is 32 bits (4 bytes) on 32-bit Linux and 64 bits (8 bytes) on 64-bit Linux.
How can I portably print a size_t value?
Use the 'z' length modifier in printf, e.g., printf("%zd\n", sizeof(int)); This is shown in the code example in the post.
Does the post cover any non-Intel architectures?
No, the post explicitly limits itself to Intel architecture, though it mentions that ARM results can be checked separately.