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 ...

Get Smaller C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.