4 ms·
> The big design mistake in C was "pointer" and "array" being the same thing syntactically. Couldn't agree more. I actually tend to think that C is totally fi
by mpweiher 8y ago
> The big design mistake in C was "pointer" and "array" being the same thing syntactically.
Couldn't agree more. I actually tend to think that C is totally fine for me, but "forget" that this is really the C that is embedded in Objective-C. Meaning we have basic collection classes like NSData (bytes), NSArray (objects), NSString (well, strings, not the same as bytes) that take care of these things, yet are close enough to the metal that you can still largely treat them as C.
Well, maybe not all of them, but particularly NSData.
- pjmlp 8y agoI never understood why it would be so hard to write ptr = &var[0] like in any sane systems programming language. Is saving to type those extra 4 characters worthwile the CVE mess we got into?
- mpweiher 8y agoNot sure it's quite that easy. Wouldn't you have to have a size field so the size of the array is known? What integer is the size field? And now the array is a struct, and I dimly recall that passing structures by value came later. Or do we do it all in the type-system? Except we don't really have much of one. And Pascal just showed what a dumb idea having the size of the array encoded in the type was, with functions that take arrays of different sizes incompatible with each other. Anyway, I think it's really kind of the other way around: it's not that C has arrays and pointers and wanted there to be compatibility. C doesn't actually have arrays, it only has pointers. What passes as arrays is a minimal bit of syntactic sugar that doesn't affect the semantics, which are just plain pointer semantics.
- pjmlp 8y agoIt is so hard that a large majority of system programming languages do it. That Pascal example is getting tired by now. It only applies to the first edition of ISO Pascal (superceded by ISO Extended Pascal), and improved by any systems language that was born afterwards.
- adrianmonk 8y agoThat's assuming it was about saving characters. It's possible the motivation was to save bytes at runtime. On systems whose total RAM is measured in single or double digits of kilobytes, that's a strong motivator. Another possible motivator could be simplifying the compiler implementation by making all arrays work the same way from a code generation point of view. Heap arrays have a size known only at runtime, so it makes sense to carry this size with the array, as the malloc() call does. But stack and global (and static) arrays have a size which is known at compile time, so they do not need a size carried around with them. Back then, using fixed sized arrays all over the place was common practice. Look at DOS 8.3 character filenames for example. So, dynamic heap allocation might have been viewed as something people wouldn't use constantly. And compilers were a lot simpler, so creating two different implementations for arrays might have seemed excessive.
- pjmlp 8y agoFirst of all, outside Bell Labs there were computers being programmed in high level languages since 1961, definitely much weaker computers than a PDP-11. Secondly, ptr = &array[0] is something would happen at compile time. Third, C authors seem to have a predisposition to ignore state of the art in existing languages.