static-variables

C++ Error linking in consumer file caused by static data field

房东的猫 提交于 2019-12-13 02:06:28
问题 I want to use a static global variable as a mutex. When I try to compile the following code: //header file class __declspec(dllexport) StateConservator { private: StateConservator(); StateConservator(const StateConservator&); protected: const CString m_oldConf; CContainer& m_container; static bool x_mutex; public: StateConservator(CContainer& container, const CString& conf) : m_container(container) , m_oldConf(!x_mutex? container.GetConf():_T("")) { if(!x_mutex) { x_mutex= true; m_container

Problems with static local variables with relocatable code

霸气de小男生 提交于 2019-12-12 16:16:08
问题 I am building a project which has relocatable code on bare metal. It is a Cortex M3 embedded application. I do not have a dynamic linker and have implemented all the relocations in my startup code. Mostly it is working but my local static variables appear to be incorrectly located. Their address is offset by the amount that my executable is offset in memory - ie I compile my code as if it is loaded at memory location 0 but I actually load it in memory located at 0x8000. The static local

Objective C - Static and global variable?

随声附和 提交于 2019-12-12 07:26:22
问题 In my .m file for a class named Ad , I have 3 static strings static NSString *AdStateDisabled = @"disable"; static NSString *AdStateExpired = @"expired"; static NSString *AdStateActive = @"active"; I can simply use these static variables in the current class, but i cannot call them from any other class, is there a way to make these static variables global? So for example in my viewcontroller class i can do something like. //HomeViewController.m if ([self.ad.state isEqual:Ad.AdStateDisabled])

Initializing globals with variables in C

ぃ、小莉子 提交于 2019-12-12 01:22:39
问题 I having the following variables defined at the top of my file right after my #include directives; int a = 5; int b = a; But I get a compile time error. I know that global variables implicitly have static storage duration, but I'm not sure how or if this is related to the cause of this error. 回答1: As you said, global variables implicitly have static storage duration. This is because global variables are initialised during compile time. So this is precisely the reason why you are getting an

Static variable Behaviour in Asp.Net

老子叫甜甜 提交于 2019-12-12 00:15:09
问题 I have a OperationHelper class which is as follows: public class OperationHelper { /// <summary> /// Gets or sets the Add Operation value /// </summary> public static bool AddOperation { get; set; } /// <summary> /// Gets or sets the Edit Operation value /// </summary> public static bool EditOperation { get; set; } /// <summary> /// Gets or sets the Delete Operation value /// </summary> public static bool DeleteOperation { get; set; } /// <summary> /// Gets or sets the Select Operation value

Javascript local static variable

两盒软妹~` 提交于 2019-12-11 16:46:42
问题 Not sure I completely understand answers to similar questions that I found here, so trying to be absolutely sure: I would like to have a local variable in a function, initialized only once (similar to static variables in strongly-typed languages such as C, C++, etc). Of course, I could declare it globally, but it seems better practice to have it within the scope of that function, since it is not used anywhere else. Now, here is what I do: function func(data) { func.PARAMS = [ {"name": "from",

Simple DLL created in Visual Studio 2017 doesn't load in XP [duplicate]

流过昼夜 提交于 2019-12-11 15:43:26
问题 This question already has answers here : Access violation on static initialization (2 answers) Closed last year . Platform Toolset - Visual Studio 2017 - Windows XP (v141_xp) Runtime library - Multi-threaded (no CRT dependencies) DLL loads fine on Vista+, but fails on XP SP2 (x86) with error code ERROR_NOACCESS (Invalid access to memory location) dll code: #include <windows.h> #include <string> BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul

PHP Nested Static Variable Access for Dependency Injection

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 10:24:02
问题 I would like to use this pattern to enable dependency injection in my code. I feel that it keeps with the play-doh nature of dynamic languages [1]. class A { static $FOO = 'Foo'; function __construct() { $this->foo = self::$FOO::getInstance(); } } A::$FOO = 'MockFoo'; $a = new A(); Unfortunately, this doesn't work and I get: Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in [test.php] on line 6 I can create a temporary variable to trick the parser, but is there another way?

explicit instantiation of static variable of a template class in different translation units

 ̄綄美尐妖づ 提交于 2019-12-11 03:05:24
问题 I was working with a template class that contains a static variable. The structure of code is as follows. Header.h template<class T> class Foo { public: static int count; Foo() { count++; } void printCount() { cout << count << endl; } }; template<class T> int Foo<T>::count; Source.cpp #include "Header.h" template<> int Foo<int>::count = 5; main.cpp #include <iostream> using namespace std; #include "Header.h" int main() { Foo<int> obj1; Foo<int> obj2; obj1.printCount(); obj2.printCount();

Objective-C – access extern const with a string containing its name? [duplicate]

走远了吗. 提交于 2019-12-10 23:50:10
问题 This question already has an answer here : How do I lookup a string constant at runtime in Objective-C? (1 answer) Closed 4 years ago . I have a constant defined out of class in SomeClass.h: extern NSString *const SCImportantString; @interface SomeClass @end And assign it in SomeClass.m: NSString *const SCImportantString = @"All your base are belong to us."; @implementation SomeClass @end Is there a way to access this extern constant by a string with its name? I know this is possible with