C Integer Type Sizes

The cluster discusses the variable sizes of primitive integer types like int, long, short in C across architectures (e.g., 32-bit vs 64-bit systems, Windows), minimum size guarantees, historical context, and recommendations to use fixed-width typedefs like int32_t, uint64_t from stdint.h for portability.

📉 Falling 0.3x Programming Languages
3,281
Comments
20
Years Active
5
Top Authors
#7396
Topic ID

Activity Over Time

2007
2
2008
5
2009
18
2010
59
2011
92
2012
82
2013
120
2014
126
2015
155
2016
301
2017
155
2018
254
2019
158
2020
215
2021
269
2022
405
2023
391
2024
252
2025
199
2026
27

Keywords

PITA BOOL AFAIK UNSIGNED ctype.h C99 PDP11 provides.html github.com BitIntegers.jl int integer 64 bits 32 unsigned 64 bit char types byte

Sample Comments

TorKlingberg Apr 12, 2018 View on HN

In C, you only have char, short, int, long and long long (signed and unsigned). Other integer types like uint32_t and size_t are typedefs to those. If int is 64 bits and char is 8 bits, you have to choose if short is 16 or 32 bits, and other one won't exist at all.long really should be 64 bits of 64-bit systems, and it is on Linux. Windows kept it at 32 bits to make porting existing code easier.

self_awareness Oct 9, 2023 View on HN

Isn't "int" 64-bit on some (rare) architectures?

Google234 May 20, 2021 View on HN

Int is not large enough for 64 bit system. ptrdiff Is always the correct size and is signed unlike size_t

Narishma Dec 29, 2014 View on HN

Is there a reason it wouldn't be 16 bits like in C?

Long shouldn't be avoided. The rule has always been 32-bits minimum. If that covers the range you need them you're good on every standards compliant platform, otherwise you use a different type. That is how the C native integer types are supposed to be used to maintain forward portability across different word size architectures. What is wrong is to blindly assume your types are larger than the minimum or exactly equal to the minimum.

earenndil Jan 13, 2020 View on HN

Likely targeting c89, which doesn't have the fixed-size ints (nor size_t, as the sibling suggests).

dgrunwald May 20, 2021 View on HN

There are 64 bit systems where "long int" still is only 32 bits. (most importantly: Windows x64)In general, the C integer types cannot be relied upon; typedefs like uint32_t, size_t, ptrdiff_t should always be preferred.

Sharlin Nov 29, 2018 View on HN

It may be crazy but it's not exactly without precedent. Neither C nor C++ fix the sizes of the fundamental integer types, although for backward-compatibility reasons popular 64-bit platforms still have 32-bit `int` and even `long`. But yeah, there's a reason eg. Rust has no `int` and friends but `i32` etc. instead.

jof Jan 4, 2012 View on HN

Isn't this what C99's uintptr_t type tries to address?

Anybody who cares about integer sizes in any more detail needs to use things like int32_t.