float.sizeof should be 4

Walter Bright newshound2 at digitalmars.com
Mon Sep 23 05:34:51 UTC 2024


I agree that it seems to make sense making 4 an `int`.

I remember the bad old days, when an `int` was 16 bits. The transition to 32 
bits broke an awful lot of code. Since the language does not recognize integer 
overflow, address calculations left and right would wrap around. Things like 
`malloc(n * sizeof(i))` would overflow the byte count, the malloc'd buffer would 
be too small, and malware would be injected.

The most effective solution is to make sizes a consistent type, which is size_t.

This does not eliminate the possibility of overflows, but dramatically reduces 
its incidence.


More information about the Digitalmars-d mailing list