Skip to main content
gamedev.net
🔒 Locked

static functions, declaration/defintion

Started by the_cyberlord Dec 23, 2004 at 1:07 PM 5 replies 1.1k views
Original Post
the_cyberlord
the_cyberlord
Why does this give a compiler error ?? Or am I misunderstanding the whole concept of static functions? header.h -------- static void somefunction(void); body.cpp -------- #include "header.h" static void somefunction(void) { blabla(); }
microdot
microdot
What is the error specically?
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
Jingo
Jingo
Remove the static from the definition. static functions have internal linkage, they cannot be accessed from other translation units.
the_cyberlord
the_cyberlord
Ow, so I'll never be able to put static functions in a seperate file, and use them in my main file?
doynax
doynax
Quote:
Original post by the_cyberlord
Ow, so I'll never be able to put static functions in a seperate file, and use them in my main file?

Yes, that's the whole point. You can use them to avoid naming collisions and allow the compiler to optimize slightly better (no need to export a generic version so the functions that wouldn't normally be inlined can be adapted to the current compilation unit). Another popular use is as a standard compliant substitute for inlined functions in C.
So why did you want to use one in the first place?
doynax
doynax
Quote:
Original post by Anonymous Poster
Eh, for the speed...
Try inline instead, if it's a short function and you really need the speed boost.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.