Internal functions

Sorry if this has been asked before but I don't understand why some functions are marked as internal (static). I thought that since handmade is a unity build all the functions are going to be in the same translation unit so marking them as static won't make a difference.

Edited by bimbinel on
If you don't mark function static then compiler needs to put it in special symbol table for linker to see it. We don't care about it, because linker will see only one file. So we can avoid overhead of this special symbol table. This will make compilation faster and use less memory for compiler.

In one of my previous jobs we had a tool that generated massive amount of C code with small functions (5 to 100 lines) for special math calculations. In total it was hundreds of MB of code. Initially very few functions were static, because some of them were accessed between translation units and the code generator didn't know which ones are and which ones are not accessed between translation units. The compile times were horrible. For something like ~30 files the build took more than hour, and typically compiler run out of ram and started swapping to disk (gcc in Xcode). Then we rewrote the tool to generate almost all functions static. Only the ones which were really really needed across translation units were non-static. Compile times went significantly down - something like less that a minute or so.

Edited by Mārtiņš Možeiko on
I see, thanks for that.

Why are some functions non static though? Shouldn't every function in the game be static except for the ones that the platform layer retrieves from the dll?
Yes, in current state all functions (except dll exported) can be static or inline. If some are not, then that is probably a mistake.

Edited by Mārtiņš Možeiko on