4 ms·
Probably back in 1970s `(characters, \000)` looked "elegant", and `(counter, characters)`, wasteful. This decision, if not the single most prolific, is likely
by nine_k 8y ago
Probably back in 1970s `(characters, \000)` looked "elegant", and `(counter, characters)`, wasteful.
This decision, if not the single most prolific, is likely one of the top 3 sources of security exploits in C code. All for the want of saving a few bytes.
- asdfman123 8y agoWhat, you're saying that features that made sense for a programming language designed in the 70s don't make sense in 2018?
- nine_k 8y agoNote how it's not a feature of a programming language per se, but rather a detail of implementation of a common data structure. Likely strings not being their own type but being directly represented as `char[]` also looked elegant and commendably parsimonious back in the day. Can't blame people who worked on machines with 128 kilobytes of RAM for that. They likely did not expect that their well-meaning hacks will take over most of the computing world.
- pjmlp 8y agoThe people that worked in machines 10 years older than PDP-11 managed to have safer systems languages. Still being sold today as Unisys ClearPath mainframes.
- berti 8y agoPlenty of systems still have less RAM than that (hint: microcontroller). Unsurprisingly they're overwhelmingly C.
- pjmlp 8y agoThose systems also have Basic and Pascal compilers, when one bothers to look around. https://www.mikroe.com/compilers https://www.mikroe.com/compilers Also many of those micro-controllers are more powerful than the computers where we ran CP/M on, where we had plenty of system languages to choose from. They are have become overwhelmingly C due to synergy effects.
- beagle3 8y agoUp until the early '90s, almost all the different Pascals had a (byte counter, character) string, which meant that if your string was longer than 255 bytes you had to do exactly the same kind of acrobatics that C did, and then some (for various reasons related to Pascal's type system). Then they added 16-bit strings. And eventually 32-bit strings. Which are useless to keep that 5GB file in memory you process these days. I'm not up-to-date - does pascal have a 64-bit string type? C, on the other hand, still uses the same error-prone and exploit inducing strcpy, strcat and friends - and the work for those 12GB gene texts and .csv files. C never looked elegant, but it was extremely effective in the limited memory / limited CPU days of yore, and that's why it won against e.g. Pascal.
- zerr 8y ago> that's why it won against e.g. Pascal. More like AT&T and Unix monopoly?
- pjmlp 8y agoC won because it came with an OS free of charge, with source code.
- tntn 8y agoUnix was neither open source nor free of charge. C won long before Linux came around.
- pjmlp 8y agoSure it was, just not with the FOSS licenses of today, apparently you are too young to remember. AT&T was forbidden to sell UNIX, so they provided the source code to universities at the symbolic price of $100, which was basically free when compared at how much something like VMS or z/OS would cost in licensing. When Linux came into the scene, C was already on its way out, being slowly replaced by C++ on OS/2, Windows, Mac OS, Symbian, BeOS, NewtonOS as the way to go for writing applications. The later three were even written in C++ (Newton also had NewtonScript). In 1994 we were already teaching C++ to first year CS students at my university. Proper C++, following Bjarne's ARM book, already talking about RAII and stronger type checking. It was UNIX FOSS with the assertion that portable software had to be written in C that eventually pushed C everywhere, even to the platforms that were already getting cosy with C++.
- phanikaran 8y agoCan you tell what are the other two though? I'm curious.
- nine_k 8y agoNo default runtime checks for array bounds (allows to alter arbitrary data and often code), and no default runtime checks for bounds of stack allocation ("smashing the stack"). Both easily lead to RCEs.