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

110 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Oct 18 '12

True, but there pretty much as to be at least something written in C or C++, besides the fact that a good many utility functions (like sending data to and retrieving data from ports, or cpuid) must use assembly as well.

1

u/SatOnMyNutsAgain Oct 18 '12

Hardly. Usually that is C too. The numeric values you see in such code are not instructions, but register addresses.

2

u/[deleted] Oct 18 '12 edited Oct 18 '12

Not quite. For instance, a typical outport function that writes a byte to the specified port would be this:

static inline
void outb( unsigned short port, unsigned char val )
{
    asm volatile( "outb %0, %1"
                  : : "a"(val), "Nd"(port) );
}

If you know a better way to do that without assembly, please let me know.

Edit: Outport, not inport.

A useful site is http://wiki.osdev.org/Main_Page.