Inline Functions in C

preview_player
Показать описание
References:

Support:

Feel free to use this video to make highlights and upload them to YouTube (also please put the link to this channel in the description)
Рекомендации по теме
Комментарии
Автор

Congrats for 2k subs! Love your content!

Pion
Автор

On the other hand there is link-time optimization which instructs the compiler to include call path information so the linker can perform the job of throwing away all known dead code. It works best with multiple compilation units sharing (mostly unused) library code and any level of optimization turned on (higher ones obviously favor more inlining). Still ends up a bit larger than removing everything yourself upfront in this example, but at least there are no library symbols left either.
If you feel like cheating, you can also pass -fwhole-program on GCC with single compilation unit programs like these, which makes the compiler treat everything apart from main as not-actually-extern.

DSamp
Автор

counterargument regarding inline: even if the compiler does know better than you, you are still writing code for _other humans_ as well as the compiler. Even if inline doesn't do anything, it's a helpful hint for other programmers to know that the _intent_ was for the function to be inlined.

BradenBest
Автор

Great video Alexey, really informative

peterhutt
Автор

Coming from a mathematical background I think that the hack you're using to not have scalar functions is more of a footgun than anything else.

randomsoul
Автор

You should add a macro to the generated header that specifies its semantic version, e.g. define LA_VERSION "1.0.1", or do it libc style 10001L

BradenBest
Автор

7:40 Russian Doomer music vol.9 (New Superior?)

thegabriel
Автор

You should add Generic Macros...

All C standards over C11 support it.

You can declare the functions as "UNUSED" using a macro, as is done in many C libraries. That will make the compiler not complain.

GegoXaren
Автор

It seems very unfair to judge the final executable by looking at the object files. How can the compiler remove definitions from the object files when it doesn't know how those object files will be used? Only the linker can possibly know that some definition in some object file is never used. Clearly the linker is also not removing unnecessary functions from the final executable, but by only looking at the object files we're not even giving the linker its fair chance.

Ansatz