Questions tagged [static-initialization]

Questions regarding initialization code of static members

325 questions
0
votes
1 answer

define a macro with file name

By finding-c++-static-initialization-order-problems, I want to define a macro in a header file, e.g. "check_fiasco.h", then put this header file to the top of every cpp file, as Warren Stevens' idea. However, I tried his code under linux, and it…
pepero
  • 7,095
  • 7
  • 41
  • 72
0
votes
1 answer

Is this the right way to do "local static initialization" in multithreaded environment (without C++11)

I have read this article (https://blogs.msdn.microsoft.com/oldnewthing/20040308-00/?p=40363), so i have written such code to protect the initialization of a local static object to be thread-safe. I fear of making mistakes (some logic errors) or…
Christian
  • 73
  • 6
0
votes
0 answers

How to create a static instance of a dependency injected class?

I've defined a class which takes a repository instance as the sole constructor argument. And now that I created a static instance of that class, MainViewModel the constructor arguments need to be specified. Issue: In order to specify the required…
Brian Var
  • 6,029
  • 25
  • 114
  • 212
0
votes
5 answers

Why is my const or static member not initialized?

I've been both scratching and banging my head on this one. I suspect I;m just being daft here, but I can't seem to get a const, or static, member to initialize so I can use it throughout a class. Here's an example that demonstrates my problem (or…
0
votes
1 answer

Building a static data structure from independent TUs piecemeal

I have several independently-written translation units; for the sake of discussion, each of which has a (static or extern'ed) global std::string variable. These strings may have different names, unrelated to the names of the TUs. And I don't…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
0 answers

static map initialization error - unresolved external symbol

Using Visual Studio 2015, I have been trying load a table that contains floating point values for degrees converted to radians. Since the MathFunctions class is static (static functions), I am trying to initialize the map that withholds the…
Wajih
  • 793
  • 3
  • 14
  • 31
0
votes
2 answers

C++ Initialization of static function pointer array

I want to create a static function pointer array, so I can jump to a certain function regarding a received index. Like an index jumper. So imagine a class like this: Class A { private: static void 1stFunction(); static void 2ndFunction(); …
0
votes
2 answers

Troubles with compiling, static initialization and static libraries

I have recently encountered a behavior in C++ program that I cannot entirely understand. Let me explain the behavior via simple example. 1. First static library At the very bottom of hierarchy, I have a static library - lets name it FirstLIB. This…
0
votes
1 answer

How to inject system property into static bean in configuration?

In my Spring @Configuration class I wish to inject the system property ${brand} into a static String bean called brandString. I have succeeded doing that with the workaround described here https://stackoverflow.com/a/19622075/1019830 using…
user1019830
0
votes
1 answer

static structure and static global variable in c++

There is a RPC framework, using hessian as out default serialization. Then, some clients need protobuf. In order to be compatible with those people who do not have protobuf installed, we put all protobuf supports into a single file, and compile it…
nzomkxia
  • 1,219
  • 4
  • 16
  • 35
0
votes
1 answer

PHPUnit stubbing a method for multiple instantiations

I'm writing a test for a class that creates a new version of itself and inserts it into the database. The insert method returns an id which I want to record against the original class a bit like this. class Invoice { public function…
DanielM
  • 6,380
  • 2
  • 38
  • 57
0
votes
1 answer

Is static memory cleaned up by a different thread?

So, what happened in my project was the following: I have a singleton which is defined in a usual way: Singleton* Singleton::getInstance() { static Singleton instance; return &instance; } in its constructor, this singleton object initializes a…
0
votes
3 answers

haxe uninitialized member variable inconsistent across platforms

I'm trying to cross compile an existing flash app written in haxe into javascript using openfl and haxe. Under flash I can do the following: class foo { var bar : Int; public function new() { trace(bar); //under flash prints 0,…
tesract
  • 53
  • 10
0
votes
1 answer

Order of object construction/initialization

In which order will the ctors be called? template class A { public: static std::function funcobj; }; template std::function A::funcobj = [](){}; class B : public A { public: …
Grisu47
  • 530
  • 5
  • 16
0
votes
3 answers

MISRA 9.2 initializing float and unsigned arrays

In the following lines, I'm getting different issues reported from the Parasoft C/C++ Test static analysis tool and from the IAR Embedded Workbench MISRA checker: [1] static unsigned int array_a[30] = {0U}; [2] static float array_b[20] =…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154