IEEEComputer NCCGroup
IEEEComputer NCCGroup
net/publication/347447924
Effective C
CITATIONS READS
0 9,148
1 author:
Robert C. Seacord
Woven by Toyota
91 PUBLICATIONS 1,896 CITATIONS
SEE PROFILE
All content following this page was uploaded by Robert C. Seacord on 15 February 2021.
Effective C
C
C has been either the most or sec-
ond-most popular programming
arl Sagan once said, “If you wish to make an ap- language since 2001; it was also TIOBE’s programming
ple pie from scratch, you must first invent the language of the year in 2019. C is a small, simple language
universe.” Dennis Ritchie and Ken Thompson that has remained successful by staying true to its princi-
did not invent the universe at Bell Telephone ples. C doesn’t prevent the programmer from doing what
Laboratories in 1972, but they did create a highly success- needs to be done. C programs should be fast, even if they
ful system programming language that can work with a are not guaranteed to be portable. C strives to provide
wide range of computing hardware and architectures. only one way to perform any operation. More recently, C
After 50 years, the C Language they invented remains as has worked toward making support for safety and secu-
vital and popular as ever. rity demonstrable.
System languages are designed for performance and Many developers no longer formally learn how to pro-
ease of access to the underlying hardware while providing gram in C. When I attended Rensselaer Polytechnic In-
high-level programming features. Although other lan- stitute in the early 1980s, all students learned Fortran,
guages offer newer language features, their compilers and while computer science students, who were thought to be
libraries are often written in C. C is layered directly on top capable of understanding while loops, learned WATFIV-S.
Many universities transitioned to teaching C or C++ as
Digital Object Identifier 10.1109/MC.2020.3016369
entry-level languages, although the dean of the School of
Date of current version: 21 October 2020 Computer Science at Carnegie Mellon University (CMU)
CO M PUTE R 0018-9162/ 20©2020IEEE PUBLISHED BY THE IEEE COMPUTER SOCIET Y NOVEMBER 2020 79
SOFTWARE ENGINEERING
felt C++ was too complex for under- instructional path to writing profes- LANGUAGE APPLICATIONS
graduates to study. The current ad- sional quality code. AND STRENGTHS
vanced placement computer science C is known as a systems programming
exam tests students on their knowl- WHY C? language, so it is not surprising that
edge of Java, which, in turn, became a People commonly ask if they should most operating systems—including
popular first language to teach at the learn a new language and where and Unix; the Microsoft Windows kernel;
university level. More recently, Python when it is appropriate to use that lan- Linux; the macOS kernel; and the iOS,
has become popular as an entry-level guage. This is particularly true for Android, and Windows Phone ker-
language at CMU and other univer- mature languages like C that have lost nels—are largely written in C. Most
sities. Unfortunately, this means it is that “new car smell.” Learning a new embedded system and IoT devices are
now increasingly common to get an language requires significant effort; programmed in C. Many of the Google
undergraduate degree in computer sci- mastering a language can take years open source community’s 2,000-plus
ence or related field without learning of practice. Consequently, it is worth- projects are written in C. Numerous
how to program in C. while to research the advantages and desktop applications are written in C.
C is commonly used in the develop-
ment of embedded systems because of
the efficiency of the generated code,
The need exists for an introduction to C that is the simplicity and availability of the
widely accessible but not so oversimplified that compilers, and the availability of de-
it promulgates the development of incorrect and velopment tools. C is a good choice for
highly constrained environments. For
insecure code.
example, microcontrollers are notori-
ously space constrained, ranging from
Brian Kernighan and Dennis Ritchie disadvantages of a language before megabytes of random-access and read-
published The C Programming Lan- committing to the effort. only memory (ROM) to bytes of ROM
guage4 in 1978. Frequently referred to Fundamental tradeoffs exist in and only registers for mutable state.
as K&R C (after the authors), this was computer science, where improving The engineering of these systems can
the first widely available book on the quality attributes such as security, be extremely cost sensitive, particu-
subject. In 1988, the second edition of performance, usability, safety, and larly in the case of mass-produced con-
the K&R book 5 was published to cover robustness can result in diminishing sumer devices.
the then-new ANSI C standard, partic- other properties. The C language is the Real-time environments that must
ularly with the inclusion of reference natural consequence of the language guarantee their response within spec-
material on the standard library. There designer’s goals to produce a small ified time constraints or deadlines are
have been many C language program- and optimally efficient language. The frequently written in C. Real-time sys-
ming books published since, but none ability to write machine-specific code tems frequently need to ensure that the
that stand out as a proper introduction is one of the strengths of C, but this worst-case execution time in certain
to modern, professional C language also means that programmers are not code paths is below a certain threshold
programming. required to write portable code. Lan- for a system to be correct. The thresholds
Even though the need for C pro- guages such as Java prioritize portabil- are often on the order of hundreds of mi-
grammers who can develop software ity over performance. croseconds. A wide disparity in execu-
for embedded systems, Internet of Most programming languages man- tion times makes budgeting difficult.
Things (IoT) devices, and other ap- ually allocate memory and other re- Developers need to minimize the max-
plications is on the rise, the avail- sources. C and C++ programmers manu- imum runtime, making the use of gar-
ability of C programmers is decreas- ally deallocate unused objects for greater bage-collected languages problematic.
ing. The learning path for new C control. Many programming languages, Support for arbitrary pointer arith-
language developers is twisted and such as Java, C#, D, and Go as well as most metic, manual memory management,
runs through murky waters. The scripting languages, use garbage collec- unchecked memory access, and the
need exists for an introduction to C tion to automatically reclaim memory lack of a built-in string type shift much
that is widely accessible but not so that is no longer in use by the program. of the burden for ensuring the correct-
oversimplified that it promulgates The Boehm–Demers–Weiser conser- ness, safety, and security of C language
the development of incorrect and vative garbage collector can be used as systems to the programmer. To some
insecure code. I published Effective a garbage-collecting replacement for degree, this is a natural outcome of
C: An Introduction to Professional C C malloc or C++ new, although its use is the language’s design goal of not pre-
Programming 16 to provide a direct not common. venting the programmer from doing
NOVEMBER 2020 81
SOFTWARE ENGINEERING
Erratum
I
n the article “Inference Acceleration: Adding Brawn to REFERENCE
the Brains,”1 which appeared in the June 2020 issue of 1. M. Campbell, “Inference acceleration: Adding brawn to
Computer, an incorrect URL was given for reference [1] the brains,” Computer, vol. 53, no. 6, pp. 73–76, 2020. doi:
due to a production error. The correct reference is 10.1109/MC.2020.2984870.
[1] K. Johnson, “OpenAI releases curtailed version of GPT-2
language model,” Venture Beat, Aug. 20, 2019. [On-
line]. Available: https://venturebeat.com/2019/08/20/
openai-releases-curtailed-version-of-gpt-2-langu
age-model/