liveBook · Manning

C99

As explained in Modern C

c99 is a command-line C compiler program commonly available on POSIX systems.

C99’s inline keyword permits a function definition to appear in several translation units without causing a multiple-symbol-definition error. It offers the compiler an opportunity to inline the function; it does not require inlining. section 15.1

Header definition

An inline definition can live in a header: inline toto* toto_init(toto* toto_x) { if (toto_x) *toto_x = (toto){ 0 }; return toto_x; }. If unused in a translation unit, the function can be absent from that unit’s binary. section 15.1

 1   // Inline definition in a header file.
 2   // Function argument names and local variables are visible
 3   // to the preprocessor and must be handled with care.
 4   inline 
 5   toto* toto_init(toto* toto_x) {
 6     if (toto_x) {
 7       *toto_x = (toto){ 0 };
 8     }
 9     return  toto_x;
10   }


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":1},{\"line\":1,\"ch\":2}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":1}],[{\"line\":2,\"ch\":1},{\"line\":2,\"ch\":2}],[{\"line\":3,\"ch\":1},{\"line\":3,\"ch\":2}],[{\"line\":4,\"ch\":1},{\"line\":4,\"ch\":2}],[{\"line\":4,\"ch\":5},{\"line\":4,\"ch\":11}],[{\"line\":5,\"ch\":1},{\"line\":5,\"ch\":2}],[{\"line\":6,\"ch\":1},{\"line\":6,\"ch\":2}],[{\"line\":6,\"ch\":7},{\"line\":6,\"ch\":9}],[{\"line\":7,\"ch\":1},{\"line\":7,\"ch\":2}],[{\"line\":8,\"ch\":1},{\"line\":8,\"ch\":2}],[{\"line\":9,\"ch\":1},{\"line\":9,\"ch\":2}],[{\"line\":9,\"ch\":7},{\"line\":9,\"ch\":13}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":2}]]"}
!@%STYLE%@!

Shows the inline header definition, including initialization through a pointer and the function’s return value. section 15.1

1   #include "toto.h"
2
3   // Instantiate in exactly one TU.
4   // The parameter name is omitted to avoid macro replacement.
5   toto* toto_init(toto*);


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":1}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":1}]]"}
!@%STYLE%@!

Shows the compatible declaration without inline that instantiates the function in exactly one translation unit and ensures symbol emission there. section 15.1

How Modern C covers it

How deep it goes
Explains inline semantics, pointer equality, unused definitions, compiler decisions, and the compatible declaration rule for symbol emission.
Examples
Uses a header definition and a compatible declaration placed in exactly one translation unit.
What it assumes
Assumes familiarity with functions, headers, translation units, function pointers, and compiler optimization.
What you can do after
Apply C99 inline rules to share definitions safely and ensure a function symbol is emitted when required.
How it connects
Connects inline functions with translation units, headers, function pointers, symbols, compiler optimization, and executable size.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.