Should static member functions be avoided in shared libraries?

While reading Oliveira and Stewart's book Writing Scientific Software, I came across this interesting passage:

"Shared variables are dangerous and should be avoided in shared libraries.

So, if you are writing a shared or dynamically linked library, avoid static or saved local variables and avoid global variables. "

(p. 55)

But what about static member functions? Are they equally dangerous in a shared library? Should I avoid them? Why / why not?

+6
source share
3 answers

But what about static member functions? Are they equally dangerous in a shared library?

Not at all: static member functions should not be avoided: unlike static variables, which represent the general state, static member functions are general calculations. As long as these calculations are not stateless, they are not at all dangerous.

+4
source

Static functions are not a problem. In fact, many of the functions that are commonly used in scientific software are pure mathematical functions, such as sin() , sqrt() , log() .

Static variables, on the other hand, are an indicator of the general condition and should be avoided.

+2
source

Not inherently. A static member function that does not use static state (for example, those that use only local or stream local variables) is unsafe. Such methods are often used in well-respected libraries such as boost or guava (the latest example from the java world).

+1
source

All Articles