Inline Function

A function with the identifier inline in C is called an Inline Function. Inline Function makes no function call, instead they are like macros where the place that the function called will be replaced by the function definition or the code that is inside the function. Since inline function doesn’t introduce #overhead, it is great to inline short functions especially 202202081524#. Always prefer Inline Function over function-like macro.

When using in a large codebase, compiler often compile source code into a single translation unit (TU). Inline Function, peculiarly in the header file, will avoid multiple symbol definition errors if it is used across multiple TUs, which means that pointers to such function in TUs will be considered as equal. We can say that Inline Function is visible to all TU. Furthermore, when one TU doesn’t call the Inline Function, the compiler will recognise it and will not add in the code into that TU, which will reduce the size of that particular TU.

Sometimes, we want to force the Inline Function to be compiled with the TU instead of omitted by default when not called. This could be done by using a compatible function declaration (almost identical to the Inline Function) with omitted parameter name in the source file (of course we need to include the header file that contain that function). Pay attention to the variable(s) name inside the function scope. It is wise to use unique prefix for the variable(s) in order to avoid weird macro expansion.

That being said, add the identifier inline to a function only if it is relatively stable, that is not many changes will be expected to be done on this function. If there is a change on the function, the compiler will rebuild all TU that called the function which can increase the compilation time. Additionally, Inline Function can’t access any variable or function that has identifier 202202111824 although passing the pointer of them to the function is fine.

#c