Você está na página 1de 20

TECH INF

information brought to you

Home / Programming / After All These Years, the World is Still Powered by C Programming

After All These Years, the World is


Still Powered by C Programming
- ! PROGRAMMING

Many of the C projects that exist today were started decades ago.

The UNIX operating systems development started in 1969, and its code was rewritten in C in 1972. Th
language was actually created to move the UNIX kernel code from assembly to a higher level language, w
would do the same tasks with fewer lines of code.
Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983. It bec
one of the most popular databases in the world.

In 1985 Windows 1.0 was released. Although Windows source code is not publicly available, its been stated
its kernel is mostly written in C, with some parts in assembly. Linux kernel development started in 1991, and
also written in C. The next year, it was released under the GNU license and was used as part of the G
Operating System. The GNU operating system itself was started using C and Lisp programming languages
many of its components are written in C.

But C programming isnt limited to projects that started decades ago, when there werent as many programm
languages as today. Many C projects are still started today; there are some good reasons for that.

How is the World Powered by C?

Despite the prevalence of higher-level languages, C continues to empower the world. The following are som
the systems that are used by millions and are programmed in the C language.

Microsoft Windows

Microsofts Windows kernel is developed mostly in C, with some parts in assembly language. For decades,
worlds most used operating system, with about 90 percent of the market share, has been powered by a ke
written in C.

Linux

Linux is also written mostly in C, with some parts in assembly. About 97 percent of the worlds 500 most powe
supercomputers run the Linux kernel. It is also used in many personal computers.

Mac

Mac computers are also powered by C, since the OS X kernel is written mostly in C. Every program and driver
Mac, as in Windows and Linux computers, is running on a C-powered kernel.
Mobile

iOS, Android and Windows Phone kernels are also written in C. They are just mobile adaptations of existing
OS, Linux and Windows kernels. So smartphones you use every day are running on a C kernel.

Databases

The worlds most popular databases, including Oracle Database, MySQL, MS SQL Server, and PostgreSQL,
coded in C (the rst three of them actually both in C and C++).

Databases are used in all kind of systems: nancial, government, media, entertainment, telecommunicati
health, education, retail, social networks, web, and the like.
3D Movies

3D movies are created with applications that are generally written in C and C++. Those applications need t
very ecient and fast, since they handle a huge amount of data and do many calculations per second. The m
ecient they are, the less time it takes for the artists and animators to generate the movie shots, and the m
money the company saves.

Embedded Systems

Imagine that you wake up one day and go shopping. The alarm clock that wakes you up is likely programme
C. Then you use your microwave or coee maker to make your breakfast. They are also embedded systems
therefore are probably programmed in C. You turn on your TV or radio while you eat your breakfast. Those
also embedded systems, powered by C. When you open your garage door with the remote control you are
using an embedded system that is most likely programmed in C.

Then you get into your car. If it has the following features, also programmed in C:

automatic transmission
tire pressure detection systems
sensors (oxygen, temperature, oil level, etc.)
memory for seats and mirror settings.
dashboard display
anti-lock brakes
automatic stability control
cruise control
climate control
child-proof locks
keyless entry
heated seats
airbag control

You get to the store, park your car and go to a vending machine to get a soda. What language did they us
program this vending machine? Probably C. Then you buy something at the store. The cash register is
programmed in C. And when you pay with your credit card? You guessed it: the credit card reader is, again, l
programmed in C.

All those devices are embedded systems. They are like small computers that have
microcontroller/microprocessor inside that is running a program, also called rmware, on embedded dev
That program must detect key presses and act accordingly, and also display information to the user. For exam
the alarm clock must interact with the user, detecting what button the user is pressing and, sometimes, how
it is being pressed, and program the device accordingly, all while displaying to the user the relevant informa
The anti-lock brake system of the car, for example, must be able to detect sudden locking of the tires and a
release the pressure on the brakes for a small period of time, unlocking them, and thereby preven
uncontrolled skidding. All those calculations are done by a programmed embedded system.

Although the programming language used on embedded systems can vary from brand to brand, they are m
commonly programmed in the C language, due to the languages features of exibility, eciency, performa
and closeness to the hardware.
Why is the C Programming Language Still Used?

There are many programming languages, today, that allow developers to be more productive than with C
dierent kinds of projects. There are higher level languages that provide much larger built-in libraries
simplify working with JSON, XML, UI, web pages, client requests, database connections, media manipulation,
so on.

But despite that, there are plenty of reasons to believe that C programming will remain active for a long time.

In programming languages one size does not t all. Here are some reasons that C is unbeatable, and alm
mandatory, for certain applications.

Portability and Eciency

C is almost a portable assembly language. It is as close to the machine as possible while it is almost univer
available for existing processor architectures. There is at least one C compiler for almost every exis
architecture. And nowadays, because of highly optimized binaries generated by modern compilers, its no
easy task to improve on their output with hand written assembly.
Such is its portability and eciency that compilers, libraries, and interpreters of other programming langu
are often implemented in C. Interpreted languages like Python, Ruby, and PHP have their prim
implementations written in C. It is even used by compilers for other languages to communicate with the mach
For example, C is the intermediate language underlying Eiel and Forth. This means that, instead of genera
machine code for every architecture to be supported, compilers for those languages just generate intermedia
code, and the C compiler handles the machine code generation.

C has also become a lingua franca for communicating between developers. As Alex Allain, Dropbox Enginee
Manager and creator of Cprogramming.com, puts it:

C is a great language for expressing common ideas in programming in a way that most people
comfortable with. Moreover, a lot of the principles used in C for instance, argc and argv for comm
line parameters, as well as loop constructs and variable types will show up in a lot of other langu
you learn so youll be able to talk to people even if they dont know C in a way thats common to bo
you.

Memory Manipulation

Arbitrary memory address access and pointer arithmetic is an important feature that makes C a perfect t for
system programming (operating systems and embedded systems).

At the hardware/software boundary, computer systems and microcontrollers map their peripherals and I/O p
into memory addresses. System applications must read and write to those custom memory locations to
communicate with the world. So Cs ability to manipulate arbitrary memory addresses is imperative for system
programming.

A microcontroller could be architected, for example, such that the byte in memory address 0x40008000 will b
sent by the universal asynchronous receiver/transmitter (or UART, a common hardware component for
communicating with peripherals) every time bit number 4 of address 0x40008001 is set to 1, and that after yo
set that bit, it will be automatically unset by the peripheral.

This would be the code for a C function that sends a byte through that UART:
#dene UART_BYTE *(char *)0x40008000
#dene UART_SEND *(volatile char *)0x40008001 |= 0x08

void send_uart(char byte)


{
UART_BYTE = byte; // write byte to 0x40008000 address
UART_SEND; // set bit number 4 of address 0x40008001
}

The rst line of the function will be expanded to:

*(char *)0x40008000 = byte;

This line tells the compiler to interpret the value 0x40008000 as a pointer to a char, then to dereference (
the value pointed to by) that pointer (with the leftmost * operator) and nally to assign byte value to
dereferenced pointer. In other words: write the value of variable byte to memory address 0x40008000.

The next line will be expanded to:

*(volatile char *)0x40008001 |= 0x08;

In this line, we perform a bitwise OR operation on the value at address 0x40008001 and
value 0x08 (00001000 in binary, i.e., a 1 in bit number 4), and save the result back
address 0x40008001. In other words: we set bit 4 of the byte that is at address 0x40008001. We also dec
that the value at address 0x40008001 is volatile. This tells the compiler that this value may be mod
by processes external to our code, so the compiler wont make any assumptions about the value in that add
after writing to it. (In this case, this bit is unset by the UART hardware just after we set it by software.)
information is important for the compilers optimizer. If we did this inside a for loop, for example, with
specifying that the value is volatile, the compiler might assume this value never changes after being set, and
executing the command after the rst loop.

Deterministic Usage of Resources

A common language feature that system programming cannot rely on is garbage collection, or even just dyna
allocation for some embedded systems. Embedded applications are very limited in time and memory resour
They are often used for real-time systems, where a non-deterministic call to the garbage collector canno
aorded. And if dynamic allocation cannot be used because of the lack of memory, it is very important to h
other mechanisms of memory management, like placing data in custom addresses, as C pointers a
Languages that depend heavily on dynamic allocation and garbage collection wouldnt be a t for resou
limited systems.

Code Size

C has a very small runtime. And the memory footprint for its code is smaller than for most other languages.

When compared to C++, for example, a C-generated binary that goes to an embedded device is about half
size of a binary generated by similar C++ code. One of the main causes for that is exceptions support.

Exceptions are a great tool added by C++ over C, and, if not triggered and smartly implemented, they h
practically no execution time overhead (but at the cost of increasing the code size).

Lets see an example in C++:


// Class A declaration. Methods dened somewhere else;
class A
{
public:
A(); // Constructor
~A(); // Destructor (called when the object goes out of scope or is deleted)
void myMethod(); // Just a method
};

// Class B declaration. Methods dened somewhere else;


class B
{
public:
B(); // Constructor
~B(); // Destructor
void myMethod(); // Just a method
};

// Class C declaration. Methods dened somewhere else;


class C
{
public:
C(); // Constructor
~C(); // Destructor
void myMethod(); // Just a method
};

void myFunction()
{
A a; // Constructor a.A() called. (Checkpoint 1)
{
B b; // Constructor b.B() called. (Checkpoint 2)
b.myMethod(); // (Checkpoint 3)
} // b.~B() destructor called. (Checkpoint 4)
{
C c; // Constructor c.C() called. (Checkpoint 5)
c.myMethod(); // (Checkpoint 6)
} // c.~C() destructor called. (Checkpoint 7)
a.myMethod(); // (Checkpoint 8)
} // a.~A() destructor called. (Checkpoint 9)

Methods of A, B and C classes are dened somewhere else (for example in other les). Therefore the com
cannot analyze them and cannot know if they will throw exceptions. So it must prepare to handle except
thrown from any of their constructors, destructors, or other method calls. Destructors should not throw (very
practice), but the user could throw anyway, or they could throw indirectly by calling some function or met
(explicitly or implicitly) that throws an exception.
If any of the calls in myFunction throw an exception, the stack unwinding mechanism must be able to call al
destructors for the objects that were already constructed. One implementation for the stack unwin
mechanism will use the return address of the last call from this function to verify the checkpoint number o
call that triggered the exception (this is the simple explanation). It does this by making use of an auxi
autogenerated function (a kind of look-up table) that will be used for stack unwinding in case an exceptio
thrown from the body of that function, which will be similar to this:

// Possible autogenerated function


void autogeneratedStackUnwindingFor_myFunction(int checkpoint)
{
switch (checkpoint)
{
// case 1 and 9: do nothing;
case 3: b.~B(); goto destroyA; // jumps to location of destroyA label
case 6: c.~C(); // also goes to destroyA as that is the next line
destroyA: // label
case 2: case 4: case 5: case 7: case 8: a.~A();
}
}

If the exception is thrown from checkpoints 1 and 9, no object needs destruction. For checkpoint 3, b and a m
be destructed. For checkpoint 6, c and a must be destructed. In all cases the destruction order mus
respected. For checkpoints 2, 4, 5, 7, and 8, only object a needs to be destructed.

This auxiliary function adds size to the code. This is part of the space overhead that C++ adds to C. M
embedded applications cannot aord this extra space. Therefore, C++ compilers for embedded systems o
have a ag to disable exceptions. Disabling exceptions in C++ is not free, because the Standard Template Lib
heavily relies on exceptions to inform errors. Using this modied scheme, without exceptions, requires m
training for C++ developers to detect possible issues or nd bugs.

And, we are talking about C++, a language whose principle is: You dont pay for what you dont use. This incre
on binary size gets worse for other languages that add additional overhead with other features that are
useful but cannot be aorded by embedded systems. While C does not give you the use of these extra feature
allows a much more compact code footprint than the other languages.

Reasons to Learn C
C is not a hard language to learn, so all the benets from learning it will come quite cheap. Lets see som
those benets.

Lingua Franca

As already mentioned, C is a lingua franca for developers. Many implementations of new algorithms in book
on the internet are rst (or only) made available in C by their authors. This gives the maximum poss
portability for the implementation. Ive seen programmers struggling on the internet to rewrite a C algorithm
other programming languages because he or she didnt know very basic concepts of C.

Be aware that C is an old and widespread language, so you can nd all kind of algorithms written in C around
web. Therefore youll very likely benet from knowing this language.

Understand the Machine (Think in C)

When we discuss the behavior of certain portions of code, or certain features of other languages, with colleag
we end up talking in C: Is this portion passing a pointer to the object or copying the entire object? Could
cast be happening here? And so on.

We would rarely discuss (or think) about the assembly instructions that a portion of code is executing w
analyzing the behavior of a portion of code of a high level language. Instead, when discussing what the mac
is doing, we speak (or think) pretty clearly in C.

Moreover, if you cant stop and think that way about what you are doing, you may end up programming
some sort of superstition about how (magically) things are done.
Work on Many Interesting C Projects

Many interesting projects, from big database servers or operating system kernels, to small embedded
applications you can even do at home for your personal satisfaction and fun, are done in C. There is no reason
stop doing things you may love for the single reason that you dont know an old and small, but strong and tim
proven programming language like C.

Conclusion
The Illuminati doesn't run the world. C programmers do.

The C programming language doesnt seem to have an expiration date. Its closeness to the hardware, g
portability and deterministic usage of resources makes it ideal for low level development for such thing
operating system kernels and embedded software. Its versatility, eciency and good performance makes
excellent choice for high complexity data manipulation software, like databases or 3D animation. The fact
many programming languages today are better than C for their intended use doesnt mean that they beat C i
areas. C is still unsurpassed when performance is the priority.

The world is running on C-powered devices. We use these devices every day whether we realize it or not. C is
past, the present, and, as far as we can see, still the future for many areas of software.

About the author

Daniel Angel Muoz Trejo

Source: toptal.com

1 Repost 1

Share on Facebook Share on Twitter Share on Google Plus

RELATED POSTS

After All These Years,


the World is...

After All These Years,


the World is...
7 comments

Add a comment as Balemarthty Vamsi

Top comments

Nigel Evans 23 minutes ago - Shared publicly


C and maybe now C/C++ are the denitive platform development languages, but they have
rightly been overtaken in the application space by "productivity languages" like c#, java, python,
html/javascript which is were most of the work is.
The article doesn't mention the dominance of C/C++ in the game space.

1 Reply

Thomas Vidal 24 minutes ago - Shared publicly


Taught myself C in high school in 1989 and must have spent a king's ransom on books that I
read during every second of my free time. Never looked back. I know a language is just a tool
and real programmers use the perfect tool for the job. But I have always loved this tool -- the way
I love my multimeter -- and I really like solving problems using it. I don't know of any other
language that forces you to understand how computers work the way that C does. And I like that
part about it, too. (I'm a trial lawyer today, and just fool around with code compared to the pros,
1 Reply
so just take this as my two cents.)

TTK Droid shared this via Google+ 1 day ago - Shared publicly
1 Reply

Balaji Rajagopalan 2 days ago - Shared publicly


though I love the post, the c/c++ jobs are really few and niche these days.

1 Reply

Calin Grecu 3 days ago - Shared publicly


Amen

1 Reply
Evan Gatchell 3 days ago - Shared publicly
Also, IoT is rapidly emerging, and microcontroller programming is done almost exclusively with
some avor of C.

1 Reply

Howard B 2 days ago - Shared publicly


To control the data! To really control the data! Your way! A new way! Not in any library call as yet!
This is the reason why Linux Adoption has taken the world by storm! Robbed Microsoft of too
many of its Users! Not in the desktop pc world! But, in the hip, mobile world! That has then
caused many a Windows pc to be pushed outside a home and onto a curb!

However! To create your own dvd of world class level of behavior and appearance can not be
Reply handheld device! A pc with dvd drives is still whats needed here. Where the
done on1no mobile
authoring of such can be done at home now! Its look and performance is of the store bought

Home Older P
LIKE OUR FACEBOOK
PAGE

FOLLOWERS

SUBSCRIBE WITH US

Enter your email address:

SUBSCRIBE

Shop Now

Higher Level Thinking


Questions: Language Ar
By Christa Robinson, Laurie Ka
$19.00
(2)

Oracle Database 11g SQ


(Oracle Press)
By Jason Price (Paperback - N
$59.00 $31.32
(27)
Shop Now

Higher Level Thinking


Questions: Language Ar
By Christa Robinson, Laurie Ka
$19.00
(2)

Oracle Database 11g SQ


(Oracle Press)
By Jason Price (Paperback - N
$59.00 $31.32
(27)

OUR SPONSOR

POPULAR POSTS

After All These


Years, the
World is Still
Powered by C
Programming
Many of the C projects that exist
today were started decades ago.
The UNIX operating systems
development started in 1969, and
it...

Unlimited
Scale and Free
Web Hosting
with GitHub Pages and
Cloudflare
I have a secret that saves my
clients a ton of money, keeps their
website secure, and has built-in
backups. The secret: I make thei...

Top 10 Most
Common
Mistakes That
Android
Developers Make
Android. Whats not to like about
this platform? Its free, its
customizable, its rapidly growing
and its available not just on you...

California
Paves the Way
for Cars With
Empty Driver's
Seats
Officials in California proposed
new rules on Friday that would let
companies test autonomous cars
on public roads with no human
driver...

Hughes Boosts
Satellite ISP
Speeds
Satellite internet is
speeding up, but alas, that doesn't
mean it's getting cheaper.
HughesNet announced its fifth-gen
technolog...

TBC
BLOG SHARES

Copyright 2015 TECH INFO

DISCLAIMER:

This website claims no credit for any images posted on this site unless otherwise noted. Images on this website are
copyright to its respectful owners.

If there is an image appearing on this website that belongs to you and do not wish for it appear on this site, please e-mail us
at ask4ebuka@gmail.com with a link to said image and it will be promptly removed.

Created By Sora Templates and My Blogger Themes


Distributed By Blogger Templates

Você também pode gostar