4 ms·
If you think about it, I think its a little bit a fault of the language (AFAIK the C specification) defining basic integer types too loose. What is the advanta
by zeptomu 9y ago
If you think about it, I think its a little bit a fault of the language (AFAIK the C specification) defining basic integer types too loose.
What is the advantage of having "int", "long" types that just give minimum byte requirements (with associated storage classes, etc.) instead of more specified types like int32_t and uint8_t? In the end you deal with fixed-size integers or not (using some bignum library), but if you deal with them you have to take their byte length into acount in your code anyway I would say (to deal with overflows and stuff).
- deleted 9y ago[deleted]
- nnethercote 9y agoI think the minimum sizes were chosen because of a combination of (a) there was a much greater variety of hardware available then, and (b) people hadn't learned that fixing these sizes is better.
- mjevans 9y agoThey were that flexible because you'd compile ONE program ONCE for (any ported) platform and that was that. It took a little while, but eventually C got https://en.wikibooks.org/wiki/C_Programming/stdint.h https://en.wikibooks.org/wiki/C_Programming/stdint.h (in C99 :( ).
- pjmlp 9y ago> They were that flexible because you'd compile ONE program ONCE for (any ported) platform and that was that. If it was ever so simple, specially given UB and compiler specific semantics across all those compilers and operating systems on the 90's (before C was hardly relevant outside UNIX).
- __s 9y agohttp://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdi... stdint even includes 'int with at least x bits' & 'fastest int type with at least x bits'
- cesarb 9y ago> What is the advantage of having "int", "long" types that just give minimum byte requirements instead of more specified types like int32_t and uint8_t? The advantage is that these more specific types might not even exist. For instance, some machines had 36-bit words, so a 32-bit type would have to be emulated, at the cost of extra instructions.