static-functions

static member function and thread-safety

不羁岁月 提交于 2019-12-04 02:29:38
In C++, when you have local variables in a static member function, does it mean those local variables are also implicitly static or are they really local? example: static void myClass::somefunc(int someint) { int myint = someint; // is myint really a local variable or does it change due to the static qualifier at function level? } Also, different threads from a thread pool running this function, does myint need to be protected by a lock? assuming that all values passed to it are different and have no relation to each other. EDIT: Thanx for the answers. Now what if I passed in a boost::shared

Static functions in Linux device driver?

*爱你&永不变心* 提交于 2019-12-04 02:19:39
Is there a reason why most function definition in device driver in linux code is defined as static? Is there a reason for this? I was told this is for scoping and to prevent namespace pollution, could anyone explain it in detail why static definition is used in this context? Functions declared static are not visible outside the translation unit they are defined in (a translation unit is basically a .c file). If a function does not need to be called from outside the file, then it should be made static so as to not pollute the global namespace. This makes conflicts between names that are the

Static Virtual functions in c++

末鹿安然 提交于 2019-12-03 11:07:51
I have a base class and a derived one and I want to change base functions while keeping them static as they should be passed to other functions as static. How can I do that? The ATL framework gets around the limitation of no virtual statics by making the base class be a template, and then having derived classes pass their class type as a template parameter. The base class can then call derived class statics when needed, eg: template< class DerivedType > class Base { public: static void DoSomething() { DerivedType::DoSomethingElse(); } }; class Derived1 : public Base<Derived1> { public: static

PHP constructors and static functions

早过忘川 提交于 2019-12-03 10:27:15
I'm a bit confused on how constructors work in PHP. I have a class with a constructor which gets called when I instantiate a new object. $foo = new Foo($args); __construct($params) is called in the class Foo and it executes the appropriate initialization code. However when I use the class to call a static function, the constructor is called again. $bar = Foo::some_function(); //runs the constructor from Foo This causes the constructor to execute, running the object initialization code that I intended only for when I create a new Foo object. Am I missing the point of how constructors work? Or

Static functions in Linux device driver

冷暖自知 提交于 2019-11-29 23:18:11
Why is it that every function in most device drivers are static? As static functions are not visible outside of the file scope. Then, how do these driver function get called by user space applications? Remember than in C everything is addresses. That means you can call a function if you have the address. The kernel has a macro named EXPORT_SYMBOL that does just that. It exports the address of a function so that driver functions can be called without having to place header declarations since those functions are sometimes not know at compile time. In cases like this the static qualifier is just

Does a static function need the static keyword for the prototype in C?

荒凉一梦 提交于 2019-11-29 22:10:24
My C programming book says that when I want to create a static function, I need to put the static keyword in front of the function definition . It doesn't mention anything explicitly about the prototype. Also, the examples don't use prototypes and simply put the static functions at the top of the file (so that they don't need prototypes I am assuming). So, does a static function need the static keyword for the prototype? Or do I only put it in front of the definition? No. A function declaration (prototype or even the definition) can omit the keyword static if it comes after another declaration

Static functions in Linux device driver

混江龙づ霸主 提交于 2019-11-28 20:35:37
问题 Why is it that every function in most device drivers are static? As static functions are not visible outside of the file scope. Then, how do these driver function get called by user space applications? 回答1: Remember than in C everything is addresses. That means you can call a function if you have the address. The kernel has a macro named EXPORT_SYMBOL that does just that. It exports the address of a function so that driver functions can be called without having to place header declarations

Does a static function need the static keyword for the prototype in C?

…衆ロ難τιáo~ 提交于 2019-11-28 18:27:57
问题 My C programming book says that when I want to create a static function, I need to put the static keyword in front of the function definition . It doesn't mention anything explicitly about the prototype. Also, the examples don't use prototypes and simply put the static functions at the top of the file (so that they don't need prototypes I am assuming). So, does a static function need the static keyword for the prototype? Or do I only put it in front of the definition? 回答1: No. A function

Static member functions error; How to properly write the signature?

﹥>﹥吖頭↗ 提交于 2019-11-28 15:50:02
I am getting an error when trying to compile my code in g++ using the current signature: cannot declare member function static void Foo::Bar(std::ostream&, const Foo::Node*) to have static linkage My question is twofold: Why does it not Compile this way? What is the correct signature, and why? Signatures have always been the death of me when using C++ Edit: Here is the class header file, as well: class Foo { public: Foo(); ~Foo(); bool insert(const Foo2 &v); Foo * find(const Foo2 &v); const Foo * find(const Foo2 &v) const; void output(ostream &s) const; private: //Foo(const Foo &v); //Foo&

C API function callbacks into C++ member function code

谁都会走 提交于 2019-11-28 11:08:08
So, I'm using the FMOD api and it really is a C api. Not that that's bad or anything. Its just it doesn't interface well with C++ code. For example, using FMOD_Channel_SetCallback( channel, callbackFunc ) ; It wants a C-style function for callbackFunc , but I want to pass it a member function of a class. I ended up using the Win32 trick for this, making the member function static. It then works as a callback into FMOD. Now I have to hack apart my code to make some of the members static, just to account for FMOD's C-ness. I wonder if its possible in FMOD or if there's a work around to link up