Handmade Hero»Forums»Code
Thompson Lee
20 posts
None
[Day21~Day23] Static function in Headers Confusion
Edited by Thompson Lee on
Before Day 21, all of the codes I followed with Casey can be compiled and built without much fuss on Visual Studio 2013.

On Day 21, just as Casey started to switch over to breaking up the project to compile EXE and DLL separately, I realized that I had a serious issue with my codes. "Static functions are declared but not defined" errors are everywhere when I started to touch the #includes.

I forgot when Casey separated Win32 specific codes and Handmade Hero codes apart, but I do know that Casey declared a lot of static functions (internally static functions) throughout the code.

How did Casey do it with static functions in header files?

EDIT:

I meant to ask about declaring static functions in the header files. The functions being declared are GameUpdateAndRender() and GameGetSoundSamples().

Does it have to do with how
1
#include "handmade.cpp"
works in a way such that the static functions defined there can be used in other CPP files, making static function definitions be accessible throughout the translation units?
Roderic Bos
70 posts
[Day21~Day23] Static function in Headers Confusion
Take a look at the warnings casey disabled in the build command file. He explicitly disabled that warning I think.
Thompson Lee
20 posts
None
[Day21~Day23] Static function in Headers Confusion
That is a warning? It can't be...

I created a brand new C++ project, and created a static function declaration in the header, similar to Casey's GameUpdateAndRender function. VS didn't compile, saying that static function is declared but not defined.

It is the same error I am getting when I move around the codes for the #includes in the win32_handmade.cpp.
Mārtiņš Možeiko
2559 posts / 2 projects
[Day21~Day23] Static function in Headers Confusion
About which function is warning about? In which file it is defined? And where declared? How are you including files?
Thompson Lee
20 posts
None
[Day21~Day23] Static function in Headers Confusion
Edited by Thompson Lee on
About which function is warning about?

GameUpdateAndRender and GameGetSoundSamples.


In which file it is defined?


handmade.cpp

And where declared?


handmade.h

How are you including files?

1
2
#include "win32_handmade.h"
#include "handmade.cpp"


It is located in main.cpp. I am guessing main.cpp is win32_handmade.cpp.
Michael Nicolella
2 posts
[Day21~Day23] Static function in Headers Confusion
'static' means 'local to translation unit', and so the function has 'internal linkage' and so the linker won't expose the name, and therefore won't be able to find the definition in the other object file.

The solution here is to remove 'static', it's not what you meant to communicate.
Thompson Lee
20 posts
None
[Day21~Day23] Static function in Headers Confusion
Ah I see. That fixes the #includes issue I was having.