My int is too big
tedunangst.com
tedunangst.com
The one argument I've seen is there would be no 32 bit type (since the next smallest integer, ie. short, would be 16 bit), but a compiler could easily have a __builtin_int32 mapped to C99 standard int32_t etc.
In C code that we write, we have a rule that every use of plain 'int' must be justified - it's a "code smell". Most places where 'int' is used should be replaced with 'size_t' (if used as an index to an array), or a C99 int32_t etc.
[0] https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_m...
[1] https://gist.github.com/rygorous/e0f055bfb74e3d5f0af20690759...
Try storing a few billion of them, they're half the size.
> In C code that we write, we have a rule that every use of plain 'int' must be justified - it's a "code smell"
Current MISRA C requires this.
But I could see it being a useful replacement for UTF-32... If you need to be able to calculate code points in constant time, and you don't mind wasting one bit out of every 64. Self synchronizing, constant time code point count from buffer size, and close to as space efficient as UTF-16, but with none of the surrogate mess.
I don't think that is a fair summary of your link at all.
First of all, the conclusion of that link's analysis is that there is no performance penalty in this case, because the compiler exploits undefined behavior to eliminate any penalty it might otherwise have caused.
Secondly, 32-bit instructions on x64 are smaller than 64-bit instructions. For example "inc eax" is a 2-byte instruction, but "inc rax" is 3 bytes. This is because 64-bit instructions need a REX prefix.
Also, as others have mentioned, there is the issue of RAM usage.
I'm not arguing that 32-bit integers are superior overall. I'm just saying that 64-bit integers aren't strictly better in terms of efficiency. For cases that will never need more than 32 bits, a 32-bit integer is probably better.
The reasoning I have always heard is to keep RAM usage constant. If you have a standarts complient C program that uses primarily int as datatype, then with 64 bit ints the 64 bit version of the program uses twice as much memory as the 32 bit version of the same program.
I'm not sure I would call it a great reason, but 32 bit ints may have been the pragmatic thing to do.
I completely disagree (except with the size_t bit - I agree with that). In my view, it's usages of int32_t and similar that should be justified: why you do you need exactly 32 bits and 2s complement representation - why does at least 32 bits and unspecific representation not suffice?
Also I didn't say that you should never use 'int'. Yesterday I had to use 'int' because the sscanf %n pattern requires it, ironically an example of exactly what I'm talking about -- it won't be able to handle strings longer than ~2^31 bytes. But in this case the string comes from a place where we know it cannot exceed this limit, so we're OK.
Because that doesn't help you. Static reasoning becomes harder. Dynamic checks (pretending the exact size is unknown) are possible but .. the exact size is statically known (just not to the programmer). It is a waste.
The sentiment is right, but the solution is metaprogramming, not unhelpfully underspecified types.
I'm a pretty high-level language user (read: I don't do C, et al), so when I read stuff like this it always makes me cringe and be happy Hickey decided to keep it simple. 64 bits, everywhere! (God save us when things go to 128)
That will take a while. And even then, people will likely keep using 64 bits for most things.
But, it takes longer each time. With exponential growth (e.g. Moore's Law) then you use up bits linearly. If you double every two years, then you use one bit every two years. That means we have about 32 years from when 32-bit became inadequate to when 64-bit becomes inadequate.
We currently have supercomputers with tens of gigabytes per processor and tens of thousands of processors. Already up to 51 bits. We're also working out fast persistent storage like NVMe and crosspoint that allow us to attach a board with terabytes where we used to attach gigabytes of DRAM. Combine those two and you can max out a 64 bit address space with current technology, let alone tomorrow's technology.
Then again, super computers aren't really running the same architecture as the rest of us.
> Then again, super computers aren't really running the same architecture as the rest of us.
Sure, but there are pushes to make datacenters act more like a giant computer, so there are niceties to a shared address space that aren't restricted to traditional supercomputers.
(Please don't make the obvious reply.)
< simcop2387> farnsworth: eta[16 EiB, 19200 MiB/s] - #now# -> "years"
< farnsworth> simcop2387: 2177.63532452879 years
based on marketing info on DDR4. So at the very least it's going to take a while before we even have to worry about a max of 16EiB in address space.So these would still have been bugs under the JVM too - crashing from an out-of-bound array access or failing to allocate a stupendously large number of objects. The JVM would stop them from turning into potential arbitrary code execution, though (as some, but not all, of these bugs did).
What if you need to represent 2^64? Bignums everywhere!
as usual, tim gets all the credit ;)
(i mean, he did send the email)