Skip to main content
gamedev.net
🔒 Locked

small question

Started by flutey May 23, 2006 at 3:51 AM 8 replies 850+ views
Original Post
flutey
flutey
what is the difference between a global function which is static, and another which isnt for example inline static DoSomething() { } and inline DoSomething() { } ???
RidiculousX
RidiculousX
Static fuctions are only used in classes (I may be wrong). You can not declare a static function outside of a class (I tried). The main difference between a static function and a nonstatic function is that the static function lacks a this pointer (but that doesn't keep you from passing one in). Static functions only have access other members of the class it belongs to.

By the way, the functions you gave are missing a return type. [smile]
moeron
moeron
You can have static functions outside of classes. AP had it right about it being a visibility issue...

[edit]
beaten
moe.ron
Nitage
Nitage
In C:
static functions may be declared outside of classes, doing so hides the function definition from other translation units

In C++:
The use of the static keyword to denote a translation unit local function is depracated. Use an anonymous namespace instead.

Symphonic
Symphonic
Funnily enough, the example the OP gave is nearly a non-example, because inlined functions are not compiled independently and are therefore not found in the symbol table for the object file anyway. Of course, many compilers will provide a compiled version for debug mode so that the debugger can step through the inlined function, but this is not required.

inline static foo bar();

would be equivalent to

inline foo bar();

but

static foo bar();

is not exported to the symbol table, whereas

foo bar();

is.

Of course, the behaviour of the static keyword inside a class declaration is totally different, thankyou Bjarne!
Geordi
George D. Filiotis

Topic Locked

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

Sign in to reply to this topic.