So I got into fundamental data types and I was left with one thing that I'm confused about - if I was going to build a 64-bit program, would I have to use data types specifically made for 64-bit architecture? I did some research and turns out that 64-bit optimized version of integer would be long long int. Or it doesn't matter and I can do fine with those data types I've learned already?
1 Answers
You may find that some types have different sizes than you're used to. For example, a 32-bit Solaris environment has 4-byte long
, but a 64-bit Solaris environment has 8-byte long
. Meanwhile, this isn't the case in Visual Studio, which retained 4-byte long
.
This is why, if you are relying on extreme range for integer types and need to be completely cross-platform, you should favour more specific types like uint64_t
. Otherwise, though, you shouldn't need to worry about this.
Similarly, you'll find that pointer types are no longer 32-bit, but 64-bit, so that they can hold all possible addresses on your shiny new 64-bit system. This shouldn't affect you unless you've done something wrong.
Don't worry about "optimisation" unless you have a serious need to eke out every last nanosecond and you can do better than your compiler, which is unlikely. Just write a descriptive, expressive program that signals your intent, as you always have.
For reference, though, you can look up your platform, environment and compiler, to find out what size the fundamental types have there. It can differ across all three.

- 17,071
- 2
- 21
- 35
-
This has always been a mess in C/C++. It would have been MUCH better (IMHO) to make an int 32 Bit long and a long 64 Bit. That would have avoided a lot of problems – U. W. Dec 08 '20 at 14:51
-
1@U.W. The idea was not to constrain the language to the 32-bit or even 8-bits-per-byte paradigm, but to have fundamental types of size natural to the platform you're programming. This made quite a lot of sense, though I would tend to agree in modern times that the benefits have been eclipsed by the advent of cross-platform programming and a range of mainstream platforms with widely similar properties. – Asteroids With Wings Dec 08 '20 at 14:52
-
Well, "we did not know better" is the only excuse today. but defining the most basic data type with a, how can I say this, *flexible* size must be considered a big mistake today and the source of many subtle bugs. Just consider the problem of using an int as an index when you really should use a size_t... – U. W. Dec 11 '20 at 11:39
-
@U.W. I don't think that's reasonable. It's not that "we did not know better", it's that the computing ecosystem was _completely_ different back then. It is true that using `int` instead of `size_t` for indexes is a bug, but that was always the case: it was then and it still is now. – Asteroids With Wings Dec 11 '20 at 11:45