News for hackers. Stuff that matters.
Re:Fil-C: A memory-safe C implementation by ummonk on Tuesday October 28, 2025 @06:23PM (#45740047)
Couldn’t one just make long bigger then to make it match?
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @06:36PM (#45740183)
Maybe so; I haven't tried. Probably a lot less code depends on unsigned long wrapping at 2⁶⁴ than used to depend on unsigned int wrapping at 2¹⁶, and we got past that. But stability standards were lower then. Any code that runs on both 32-bit and 64-bit LP64 systems can't be too dependent on the exact sizeof long, and sizeof long already isn't sizeof int the way it was on 32-bit platforms.
Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @02:26PM (#45751009)
I'd actually keep it still wrapping at 2^64, with the extra metadata not participating in arithmetic operations...
Re:Fil-C: A memory-safe C implementation by cryptonector on Wednesday October 29, 2025 @01:08AM (#45742848)
It's going to break stuff one way or another.
Re:Fil-C: A memory-safe C implementation by jibal on Wednesday October 29, 2025 @02:08AM (#45743207)
There's a lot of code that makes assumptions about the number of bytes in a long rather than diligently using sizeof ... remember, the whole point here is low quality code.
Re:Fil-C: A memory-safe C implementation by kbolino on Wednesday October 29, 2025 @09:57AM (#45746913)
That seems worse.

For all the wrong code that assumes long can store a pointer, there's likely a lot more wrong code that assumes long can fit in 64 bits, especially when serializing it for I/O and other-language interop.

Also, 128-bit integers can't fit in standard registers on most architectures, and don't have the full suite of ALU operations either. So you're looking at some serious code bloat and slowdowns for code using longs.

You've also now got no "standard" C type (char, short, int, long, long long) which is the "native" size of the architecture. You could widen int too, but a lot of code also assumes an int can fit in 32 bits.

Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @12:54PM (#45749588)
No, it should only do arithmetic on the first 64 (or 32) bits. The extra metadata should be copied unchanged.
Re:Fil-C: A memory-safe C implementation by kbolino on Wednesday October 29, 2025 @01:29PM (#45750188)
Ok, I think I follow. You'd widen the type under the hood but not expose this fact to user code.

However, most longs are just numbers that have no metadata. I guess you'd set the metadata portion to all zeroes in that case. This feels like a reified version of Rust's pointer provenance, and I think you would have to expose some metadata-aware operations to the user. In which case, you're inviting some code rewrites anyway.

While not as bad as the register/ALU ops issue, you're still making all code pay a storage size penalty, and still adding some overhead to handle the metadata propagating through arithmetic operations, just to accommodate bad code, plus it complicates alignment and FFI.

Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @02:24PM (#45750992)
It would still be exposed to user code that checks its size with sizeof, but yeah the long would only have numerical values between 2^-63 and 2^63-1.

And yes, there would still be some overhead for storing and propagating the metadata, and struct alignment would change and FFI wouldn't work with longs.

Re:Fil-C: A memory-safe C implementation by ummonk on Thursday October 30, 2025 @07:35AM (#45758881)
Err I meant -2^63, that’s embarrassing.
Re:Fil-C: A memory-safe C implementation by kragen on Saturday November 01, 2025 @11:11AM (#45782266)
Heh. I missed that.