5 ms·
D made a great leap forward with the following: 1. bytes are 8 bits 2. shorts are 16 bits 3. ints are 32 bits 4. longs are 64 bits 5. arithmetic is 2's com
by WalterBright 2y ago
D made a great leap forward with the following:
1. bytes are 8 bits
2. shorts are 16 bits
3. ints are 32 bits
4. longs are 64 bits
5. arithmetic is 2's complement
6. IEEE floating point
and a big chunk of wasted time trying to abstract these away and getting it wrong anyway was saved. Millions of people cried out in relief!
Oh, and Unicode was the character set. Not EBCDIC, RADIX-50, etc.
- gerdesj 2y ago"1. bytes are 8 bits" How big is a bit?
- poincaredisk 2y agoA bit is either a 0 or 1. A byte is the smallest addressable piece of memory in your architecture.
- elromulous 2y agoTechnically the smallest addressable piece of memory is a word.
- asveikau 2y agoDepends on your definition of addressable. Lots of CISC architectures allow memory accesses in various units even if they call general-purpose-register-sized quantities "word". Iirc the C standard specifies that all memory can be accessed via char*.
- Maxatar 2y agoI don't think the term word has any consistent meaning. Certainly x86 doesn't use the term word to mean smallest addressable unit of memory. The x86 documentation defines a word as 16 bits, but x86 is byte addressable. ARM is similar, ARM processors define a word as 32-bits, even on 64-bit ARM processors, but they are also byte addressable. As best as I can tell, it seems like a word is whatever the size of the arithmetic or general purpose register is at the time that the processor was introduced, and even if later a new processor is introduced with larger registers, for backwards compatibility the size of a word remains the same.
- mort96 2y agoEvery ISA I've ever used has used the term "word" to describe a 16- or 32-bit quantity, while having instructions to load and store individual bytes (8 bit quantities). I'm pretty sure you're straight up wrong here.
- bregma 2y agoThe difference between address A and address A+1 is one byte. By definition. Some hardware may raise an exception if you attempt to retrieve a value at an address that is not a (greater than 1) multiple of a byte, but that has no bearing on the definition of a byte.
- throw16180339 2y agoThat's only true on a word-addressed machine; most CPUs are byte-addressed.
- Nevermark 2y agoWhich … if your heap always returns N bit aligned values, for some N … is there a name for that? The smallest heap addressable segment?
- CoastalCoder 2y ago> How big is a bit? A quarter nybble.
- thamer 2y agoThis doesn't feel like a serious question, but in case this is still a mystery to you… the name bit is a portmanteau of binary digit, and as indicated by the word "binary", there are only two possible digits that can be used as values for a bit: 0 and 1.
- seoulbigchris 2y agoSo trinary and quaternary digits are trits and quits?
- eqvinox 2y agoYes, trit is commonly used for ternary logic. "quit" I have never heard in such a context.
- euroderf 2y agoSo shouldn't a two-state datum be a twit ?
- nonameiguess 2y agoHow philosophical do you want to get? Technically, voltage is a continuous signal, but we sample only at clock cycle intervals, and if the sample at some cycle is below a threshold, we call that 0. Above, we call it 1. Our ability to measure whether a signal is above or below a threshold is uncertain, though, so for values where the actual difference is less than our ability to measure, we have to conclude that a bit can actually take three values: 0, 1, and we can't tell but we have no choice but to pick one. The latter value is clearly less common than 0 and 1, but how much less? I don't know, but we have to conclude that the true size of a bit is probably something more like 1.00000000000000001 bits rather than 1 bit.
- basementcat 2y agoA bit is a measure of information theoretical entropy. Specifically, one bit has been defined as the uncertainty of the outcome of a single fair coin flip. A single less than fair coin would have less than one bit of entropy; a coin that always lands heads up has zero bits, n fair coins have n bits of entropy and so on. https://en.m.wikipedia.org/wiki/Information_theory https://en.m.wikipedia.org/wiki/Information_theory https://en.m.wikipedia.org/wiki/Entropy_(information_theory) https://en.m.wikipedia.org/wiki/Entropy_(information_theory)
- fourier54 2y agoThat is a bit in information theory. It has nothing to do with the computer/digital engineering term being discussed here.
- sirsinsalot 2y agoThis comment I feel sure would repulse Shannon in the deepest way. A (digital, stored) bit, abstractly seeks to encode and make useful through computation the properties of information theory. Your comment must be sarcasm or satire, surely.
- fourier54 2y agoI do not know or care what would Mr. Shannon think. What I do know is that the base you chose for the logarithm on the entropy equation has nothing to do with the amount of bits you assign to a word on a digital architecture :)
- dullcrisp 2y agoAt least 2 or 3
- zombot 2y agoIf your detector is sensitive enough, it could be just a single electron that's either present or absent.
- amelius 2y agoDepends on your physical media.
- cogman10 2y agoYeah, this is something Java got right as well. It got "unsigned" wrong, but it got standardizing primitive bits correct byte = 8 bits short = 16 int = 32 long = 64 float = 32 bit IEEE double = 64 bit IEEE
- jltsiren 2y agoI like the Rust approach more: usize/isize are the native integer types, and with every other numeric type, you have to mention the size explicitly. On the C++ side, I sometimes use an alias that contains the word "short" for 32-bit integers. When I use them, I'm explicitly assuming that the numbers are small enough to fit in a smaller than usual integer type, and that it's critical enough to performance that the assumption is worth making.
- Jerrrrrrry 2y agohindsight has its advantages
- jonstewart 2y ago<cstdint> has int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, and uint64_t. I still go back and forth between uint64_t, size_t, and unsigned int, but am defaulting to uint64_t more and more, even if it doesn't matter.
- WalterBright 2y agoThat doesn't really fix it, because of the integral promotion rules.
- kazinator 2y ago> you have to mention the size explicitly It's unbelievably ugly. Every piece of code working with any kind of integer screams "I am hardware dependent in some way". E.g. in a structure representing an automobile, the number of wheels has to be some i8 or i16, which looks ridiculous. Why would you take a language in which you can write functional pipelines over collections of objects, and make it look like assembler.
- Laremere 2y agoZig is even better: 1. u8 and i8 are 8 bits. 2. u16 and i16 are 16 bits. 3. u32 and i32 are 32 bits. 4. u64 and i64 are 64 bits. 5. Arithmetic is an explicit choice. '+' overflowing is illegal behavior (will crash in debug and releasesafe), '+%' is 2's compliment wrapping, and '+|' is saturating arithmetic. Edit: forgot to mention @addWithOverflow(), which provides a tuple of the original type and a u1; there's also std.math.add(), which returns an error on overflow. 6. f16, f32, f64, f80, and f128 are the respective but length IEEE floating point types. The question of the length of a byte doesn't even matter. If someone wants to compile to machine whose bytes are 12 bits, just use u12 and i12.
- __turbobrew__ 2y agoThis is the way.
- Spivak 2y agoHow does 5 work in practice? Surely no one is actually checking if their arithmetic overflows, especially from user-supplied or otherwise external values. Is there any use for the normal +?
- dullcrisp 2y agoYou think no one checks if their arithmetic overflows?
- Spivak 2y agoI'm sure it's not literally no one but I bet the percent of additions that have explicit checks for overflow is for all practical purposes indistinguishable from 0.
- nox101 2y agoLots of secure code checks for overflow fillBufferWithData(buffer, data, offset, size) You want to know that offset + size don't wrap past 32bits (or 64) and end up with nonsense and a security vulnerability.
- stkdump 2y agoI mean practically speaking in C++ we have (it just hasn't made it to the standard): 1. char 8 bit 2. short 16 bit 3. int 32 bit 4. long long 64 bit 5. arithmetic is 2s complement 6. IEEE floating point (float is 32, double is 64 bit) Along with other stuff like little endian, etc. Some people just mistakenly think they can't rely on such stuff, because it isn't in the standard. But they forget that having an ISO standard comes on top of what most other languages have, which rely solely on the documentation.
- mort96 2y ago> (it just hasn't made it to the standard) That's the problem
- stkdump 2y agoYou are aware that D and rust and all the other languages this is being compared to don't even have an ISO standard, right?
- mort96 2y agoYeah, so their documentation serves as the authority on how you're supposed to write your code for it to be "correct D" or "correct Rust". The compiler implementors write their compilers against the documentation (and vice versa). That documentation is clear on these things. In C, the ISO standard is the authority on how you're supposed to write your code for it to be "correct C". The compiler implementors write their compilers against the ISO standard. That standard is not clear on these things.
- stkdump 2y agoI don't think this is true. The target audience of the ISO standard is the implementers of compilers and other tools around the language. Even the people involved in creating it make that clear by publishing other material like the core guidelines, conference talks, books, online articles, etc., which are targeted to the users of the language.
- bmacho 2y ago> D made a great leap forward > and a big chunk of wasted time trying to abstract these away and getting it wrong anyway was saved. Millions of people cried out in relief! Nah. It is actually pretty bad. Type names with explicit sizes (u8, i32, etc) are way better in every way.
- WalterBright 2y ago> Type names with explicit sizes (u8, i32, etc) are way better in every way Until one realizes that the entire namespace of innn, unnn, fnnn, etc., is reserved.
- bmacho 2y agoYou are right, they come with a cost.
- eps 2y agoThat's a bit self-pat-on-the-back-ish, isn't it, Mr. Bright, the author of D language? :)
- WalterBright 2y agoOf course! Over the years I've known some engineers who, as a side project, wrote some great software. Nobody was interested in it. They'd come to me and ask why that is? I suggest writing articles about their project, and being active on the forums. Otherwise, who would ever know about it? They said that was unseemly, and wouldn't do it. They wound up sad and bitter. The "build it and they will come" is a stupid Hollywood fraud. BTW, the income I receive from D is $0. It's my gift. You'll also note that I've suggested many times improvements that could be made to C, copying proven ideas in D. Such as this one: https://www.digitalmars.com/articles/C-biggest-mistake.html https://www.digitalmars.com/articles/C-biggest-mistake.html C++ has already adopted many ideas from D.
- eps 2y ago> https://www.digitalmars.com/articles/C-biggest-mistake.html https://www.digitalmars.com/articles/C-biggest-mistake.html To be fair, this one lies on the surface for anyone trying to come up with an improved C. It's one of the first things that gets corrected in nearly all C derivatives. > C++ has already adopted many ideas from D. Do you have a list? Especially for the "adopted from D" bit rather than being a evolutionary and logical improvement to the language.