When I reading some code, for integer, they use bunch of different type such as size_t, uint32, uint64
etc.
What is the motivation or purpose to do this?
Why not ju
The motivation to use them is because you can't rely on int
, short
or long
to have any particular size - a mistake made by too many programmers far too many times in the past. If you look not too far back in history, there was a transition from 16 bit to 32 bit processors, which broke lots of code because people had wrongly relied on int
being 16 bits. The same mistake was made thereafter when people relied on int
to be 32 bits, and still do so even to this day.
Not to mention the terms int
, short
and long
have been truly nuked by language designers who all decide to make them mean something different. A Java programmer reading some C will naively expect long
to mean 64 bits. These terms are truly meaningless - they don't specify anything about a type, and I facepalm every time I see a new language released that still uses the terms.
The standard int types were a necessity so you can use the type you want to use. They should've deprecated int
, short
and long
decades ago.