4 ms·
I don't think that's true. When I came of age in programming there were lots of choices already but none that offered the balance of control and speed that C ga
by jacquesm 7y ago
I don't think that's true. When I came of age in programming there were lots of choices already but none that offered the balance of control and speed that C gave. It was a very easy choice; do I invest my next two decades in Assembly, Pascal (in several flavors), Modula-2, Forth, LISP (which required unobtainable computers at the time), Basic (compiled or interpreted) or C?
UNIX had very little to do with it, only very few people were lucky enough to have access to UNIX machines but untold 100's of thousands had access to PCs or 8 bit micros. The first time I saw a UNIX machine it was an Acorn 'Unicorn' and it was so far ahead of what I could afford that it might as well not exist.
- pjmlp 7y agoSure it was, there were zero reasons to use C on CP/M, MS-DOS, Atari, Amiga, Mac. It was just another programming language fighting for developer eyes. On Windows and OS/2, although IBM and Microsoft decided to go with C for the underlying low level layers, C++ was the way to go for high level coding, C Set++, MFC. With Borland having Turbo Vision, OWL and VCL. Macs were Object Pascal territory, and when MPW got C and C++ support, PowerPlant C++ framework was the way to go. Epoch, BeOS and Symbian were also C++ territory. MS-DOS games were also adopting C++ via Watcom and its DOS extender. UNIX and the rise of FOSS, based on UNIX culture, were definitely the only reason.
- flohofwoe 7y agoIME C++ wasn't really a mainstream option until the second half of the 90's. BeOS choosing C++ for its operating system APIs was an extremely exotic choice at the time (same level of "exotic" as NeXT choosing Objective-C). And IMHO, at that time, before or around C++98, C++ didn't fix a single problem of C, but instead just added a lot of new ones (one could argue that this is still the case even today).
- zabzonk 7y ago> IME C++ wasn't really a mainstream option until the second half of the 90's I was getting paid for teaching C++ on commercial training courses in 1990 - the C++ courses were probably the most popular after C and UNIX > before or around C++98, C++ didn't fix a single problem of C Of course it did, or why would people like me have transferred wholesale from C to C++?
- pjmlp 7y agoIt was so exotic that at my university, FCT/UNL, starting in 1992 they switched the first year students to learn Pascal followed by C++. C was never taught as such, as any student was expected to know it from their C++ classes. The professor was a great teacher of what all the ways that C++ fixed C's problems, by providing his own data structures for strings, arrays, vectors, linked lists and hash tables, all with bounds checking enabled by default on his implementation. Other issues that C++ fixed over C was having implicit conversions, a proper way to allocate memory (malloc() with sizeof, really?), ability to ensure valid pointers via references.
- jstimpfle 7y agoC++ fixes many of C's problems and introduces so many more that are not fixable. ("But why don't you write const-correct code? Why don't you use move semantics? Use the rule of three!") > malloc() with sizeof, really? One tiny macro to solve 20% of all the problems people are whining about. void _alloc_memory(void **ptr, size_t numElems, size_t elemSize) { size_t numBytes = safe_multiply(numElems, elemSize); void *p = malloc(numBytes); if (p == NULL) fatal("OOM!\n"); *ptr = p; } #define ALLOC_MEMORY(ptr, numElems) _alloc_memory((ptr), (numElems), sizeof **(ptr)) int *myArray; ALLOC_MEMORY(&myArray, 25); I've been using this for years without a problem.
- jacquesm 7y agoFor a slightly improved version, place a sentinel (say a 4 byte magic number) just before and after the allocated segment. Check on FREE_MEMORY if they're still there. Not perfect but pretty good as an early warning system.
- jstimpfle 7y agoYes. Another possibility, add something with __FILE__ and __LINE__ if there are memory leaks to debug. (Never did that but it should help).
- pjmlp 7y ago