5 ms·
Legacy, there’s lots of dumb stuff in C. As you note, in modern languages the rule is generally to have fixed-size integers. Though I think there are portabili
by masklinn 4y ago
Legacy, there’s lots of dumb stuff in C. As you note, in modern languages the rule is generally to have fixed-size integers.
Though I think there are portability issues concerns, that world is mostly gone (it remains in some corners of computing e.g. dsps) but if you’re only using fixed-size integers what do you do when a platform doesn’t have that size? With a more flexible scheme, you have less issues there, however as the weirdness landscape contracts the risk of making technically incorrect assumptions (about relations between type sizes, or the actual limits and behaviour of a given type) start increasing dramatically.
Finally there’s the issue at hand here: even with fixed-size integers, “pointer” is a variable-size datum. So you still need a variable-size integer to go with it. C historically lacking that (nowadays it’s called uintptr_t), the kernel made assumptions which are incorrect.
Note that you can still get it wrong even if you try e.g. Rust believes and generally assumes that usize and pointers correspond, but that gets iffy with concepts like pointer provenance, which decouple pointer size and address space.
- mpweiher 4y ago> in modern languages the rule is generally to have fixed-size integers. Modern languages have unlimited size integers :-) "Modern" as in "since at least the 80s, more likely 70s".
- fluoridation 4y agoGood luck using those to specify the data layout of a network packet.
- josefx 4y agoYou are supposed to stream your video data as base64 encoded xml embedded in a json array.
- mpweiher 4y agoWell, for that you'd probably use a specialisation of Integer that's bounded and can thus be represented in a machine word.
- fluoridation 4y agoAnd then you'll be wasting time marshaling data between the stream and your objects because they're not PODs and so you can't just memcpy() onto them.
- kuratkull 4y agoGood luck seeing your performance drop off a very sharp cliff if you start using larger numbers than your CPU can fit into a single register.
- mpweiher 4y agoWell, in those case other languages fail. Either silently with overflows, usually leading to security exploits, or by crashing. So in either case you are betting that these cases are somewhere between rare and non-existent, particularly for your core/performance intensive code. Being somewhat slower, probably in very isolated contexts (60-62 bits is quite a bit to overflow), but always correct seems like the better tradeoff. YMMV. ¯\_(ツ)_/¯
- josefx 4y agoHow many languages actually take advantage of the fact that they could get more performance out of "small" register sized integers? You tend to lose a lot of performance to arbitrary sized integers in most languages even if your inputs are small. > but always correct seems like the better tradeoff. Not if you are dealing with time constraints. Glitchy output isn't good, but locking up the system because some buggy code path is trying to allocate a 10 GB integer can be worse.
- mpweiher 4y ago> How many languages actually take advantage of the fact that they could get more performance out of "small" register sized integers? Er...all of them? I am not aware of one that uses growable integers as their default integer representation that does not use some form of tagged pointer optimisation. > Glitchy output isn't good Hmm...understating the problem here just a tad. "In 2021, they ranked 12th in the updated Common Weakness Enumeration (CWE) list of the most common flaws, bugs, faults, and other errors in either hardware or software. The team behind the list ranked integer overflows just after “Missing Authentication for Critical Function”, due to the severity and prevalence of integer overflows." https://www.comparitech.com/blog/information-security/integer-overflow-attack/ https://www.comparitech.com/blog/information-security/intege... > Some buggy code path is trying to allocate a 10 GB integer can be worse Hmmm...overstating the problem here just a tad. Not even sure how you'd manage that, given that that would be an integer with 4 billion digits.
- raverbashing 4y ago> Legacy, there’s lots of dumb stuff in C. Yes, this, so much this Who cares what an 'int' or a 'long' is. Except for things like the size of a pointer, it's better if you know exactly what you're working with.