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.