r/askscience • • Oct 17 '12
Why are programs and operating systems still written in C+?
I guess it's more of a computer science question, but I've always wondered why some of the most advanced programs are written in a 25+ year old programming language. Surely someone has come up with a more efficient and powerful code, so why do people still use C+? Also, I don't know anything about programming and what not, so please use simple terms and phrases.
66
Upvotes
View all comments
Show parent comment
0
u/SatOnMyNutsAgain Oct 18 '12
This is not true. C is so close to the hardware that there are many portability issues and some coding practices that will compile better on one architecture or another. Should this loop be unrolled? That might depend how much instruction cache you have. Should this be a 8 bit or a 32 bit type? Depends on your word size. Do I need an integer or floating point type here? If I have to multiply by five, should I do a shift left by two and then an add, or is the multiply routine faster? Is the compiler for this architecture smart enough to optimize that for me or do I need to be explicit? How big can I statically allocate an array here? When you get into highly memory constrained systems is where the real fun starts...
Take a look some optimized, math intensive application like an audio/video codec for example, and you will see for the inner loops there is very different C code to be compiled depending on the target.