A function symbol is the linkable identity associated with a function definition. In a header, a static function creates a separate instance and symbol in each translation unit; an inline function can be defined across translation units without causing multiple-symbol-definition errors. section 15.1
TAKEAWAY: symbol identity affects both executable contents and function-pointer behavior.
- Static header functions may be instantiated separately in every translation unit; pointers to those instances need not compare equal across translation units. section 15.1
- C99 inline definitions may appear in several translation units; pointers to the same inline function compare equal, while unused definitions can be absent from a translation 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%@!
Inspect the header-style inline definition of toto_init, including its null check, structure initialization, and returned pointer. section 15.1
One translation-unit instantiation
The companion declaration omits the parameter name and marks one translation unit as the place to instantiate toto_init, complementing the inline header definition. section 15.1
