Questions tagged [static-initialization]

Questions regarding initialization code of static members

325 questions
0
votes
2 answers

template specialization/initializations and namespaces?

What are C++'s rules regarding template specialization and namespace qualification? I had some code that boiled down to the equivalent of the following, and it made me realize that I don't understand C++'s rules regarding template specialization…
0
votes
1 answer

Force scala.Predef initialization on application start without affecting the code

Initialization of scala.Predef class is lazy heavyweight operation which may cause unexpected slowdown of application and will become a trouble in situations when timing matters (like programming contests). val a = new Array[Integer](10) a(5) = 3…
FireFry
  • 125
  • 6
0
votes
3 answers

Why is Static Initialization Order Fiasco called this way?

Since Static Initialization concerns Zero-initialization and initialization with a constant expression, according the C++03 standard, I cannot see which fiasco could arise there. So, SO, why such a name, instead of eg "[Dynamic] Initialization Order…
YvesgereY
  • 3,778
  • 1
  • 20
  • 19
0
votes
1 answer

JUnit: initialization of static final attributes

Oftentimes in my unit tests I have fixtures that are read from resource files and stored into a static attribute on the test class: public class TestFoo { private static String fileContents; @BeforeClass public static void setup()…
Adam Parkin
  • 17,891
  • 17
  • 66
  • 87
0
votes
3 answers

Why is static initialization order STILL unspecified?

Doesn't a compiler have all the information it needs to generate a dependency tree of all globals and create a well defined and correct initialization order for them? I realize you could write a cyclic dependency with globals - make only that case…
David
  • 27,652
  • 18
  • 89
  • 138
0
votes
1 answer

Static initializer of shared library inside dynamic library

So I have a static library (MacOS, .a library). It's written in C++ and has static initializers in it's code like that: //myclass.hpp class MyClass { ... static MyClass *defaultValue_; static MyClass *newInitialDefaultValue(); …
peetonn
  • 2,942
  • 4
  • 32
  • 49
0
votes
6 answers

Constructors called due to static initialization

I am going through Thinking in Java by Bruce Eckel 4th Edition. In the chapter Initialization & Cleanup, page : 189 the first bullet point in the second para mentions: Even though it doesn't explicitly use the static keyword the constructor is…
gudge
  • 1,053
  • 4
  • 18
  • 33
0
votes
1 answer

How to know if Static Block Initialization has been run?

I am trying to get rid of some memory leaks. I'd like to reset all the static variables of all the classes (not only mine) from a class loader. There is a classes attribute that lists all the classes known by the ClassLoader. So I just want to loop…
poussma
  • 7,033
  • 3
  • 43
  • 68
0
votes
1 answer

How to initialize static field in template class with type of inner class

I have something like this template class Outer { public: class Inner; static Inner* x; //... class Inner { //... }; }; // Not working template Outer::Inner* Outer::x = NULL; Error I get…
abc
  • 2,371
  • 3
  • 25
  • 36
0
votes
1 answer

Powermock - @SupressStaticInitializationFor is not working

I have a class containing native methods and a static initializer which loads a dll and mocked it with powermock so that the the static initializer should be suppressed and the dll shouldn't be loaded. The class looks like this: class…
BeWu
  • 1,941
  • 1
  • 16
  • 22
0
votes
1 answer

What if a static initializer in class X invokes a method in Y, but Y's static initializers invoke a method in X to set up its static values?

This question is asked and explained in JAVA PROGRAMMING LANAGUAGE book.But i m not clear with explaination. Can someone Explain it more clearly ? Explaination in book is :: This cyclic static initialization cannot be reliably detected during…
Prateek
  • 12,014
  • 12
  • 60
  • 81
0
votes
3 answers

using static initialization blocks to improve performance

Given an existing code base being used in production containing a class A that contains a method that populates N fields of another POJO class B using setters and returns the POJO to the caller and given that all instances of class B will be…
Chetan Kinger
  • 15,069
  • 6
  • 45
  • 82
-1
votes
2 answers

How to mitigate user-facing API Effect of shared members in templated classes?

Let's say I have a type of lookup table which I can build for a given integer: class FooLookupTable { ... public: FooLookupTable(int radix) { ... } }; Then there's a class whose template parameter is that same integer, and…
-1
votes
1 answer

Do static members of a class get initialized even before static constructor gets called?

I was reading MSDN Documentation and there seems to be a contradiction. Static members are initialized before the static member is accessed for the first time and before the static constructor, if there is one, is called. also in the next…
SamuraiJack
  • 5,131
  • 15
  • 89
  • 195
-1
votes
2 answers

static map not intialized correctly?

I'm using some c++ code in a static library in a macOS App. The c++ code contains the following: static map aMap1; __attribute__((constructor)) static void initialize() { { static map aMap2; printf("map1: %d,…
Nick
  • 3,958
  • 4
  • 32
  • 47
1 2 3
21
22