Skip to Main Content
Smaller C
book

Smaller C

by Marc Loy
May 2021
Intermediate to advanced content levelIntermediate to advanced
311 pages
7h 45m
English
O'Reilly Media, Inc.
Content preview from Smaller C

Chapter 7. Libraries

One of C’s best qualities is the minimal adornment present in its compiled code. A favorite snipe at some more modern languages like Java is the size of the “Hello, World” program. Our very first program back in “Creating a C ‘Hello, World’” takes up a little over 16Kb on my Linux machine without any optimizations. Achieving the same output from a standalone executable on the same system using Java, though, requires tens of megabytes and much, much more effort to build. That’s not an entirely fair comparison since the Java hello application needs the entire Java runtime baked into the executable, but that’s also the point: C makes it easy to create lean code for a given system.

That ease is great when we’re tackling small things like “Hello, World” or even most of the examples from past chapters. But as we get ready to jump into the world of microcontrollers and Arduino, we’re left worrying about re-creating our own solutions to some pretty mundane problems. For example, we’ve written some of our own functions to compare strings. We wrote a fancier program to encode base64 content. That stuff is fun, but do we always have to do this type of work from scratch?

Happily, the answer to that question is: no. C supports the notion of using a library for quick, friendly expansion of its capabilities—without losing its lean profile for the final executable. A library is a bundle of code that can be imported into your projects to add new capabilities, like working ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming for the PIC Microcontroller: Simplifying Embedded Programming

Intermediate C Programming for the PIC Microcontroller: Simplifying Embedded Programming

Hubert Henry Ward

Publisher Resources

ISBN: 9781098100322Errata PageSupplemental Content