Questions regarding initialization code of static members
Questions tagged [static-initialization]
325 questions
1
vote
1 answer
Best initializing for an EnumSet holded by instance of E
I'm coping with some work regarding places where I used some unsafe (no type safety) String or int representations of part of the model.,
and leveraging Enum and EnumSet best practices.
One particular difficulty is this use case : an Enum where…

Henoc TheDev
- 43
- 5
1
vote
3 answers
Calling void function before main()
I wanted to know if it was possible to call a void function without using a temp variable. E.g. in the following code block...
#include
void earlyInit()
{
std::cout << "The void before the world." << std::endl;
}
int g_foo =…

StoneThrow
- 5,314
- 4
- 44
- 86
1
vote
1 answer
Private static property variable leads to null pointer exception
I have set a private static properties object to load in some configuration for my factory class in the constructor of factory class.
public class BussinessServiceFactory {
private static final BussinessServiceFactory factory = new…

Wenjie Li
- 13
- 4
1
vote
0 answers
Why does class initializer get called when calling method is not run?
I have a class in a protected/locked jar file that I have to unlock before I can use any of its classes. The class extends a class from java standard library:
ProtectedClass extends UnprotectedClass
In my unprotected code, I have the following…

Bowi
- 1,378
- 19
- 33
1
vote
1 answer
Static initialization of large map
I am statically initializing a large (~20kb) std::unordered_map
const std::unordered_map mapStringToString{
{"AAF", "ELN"}, {"ACT", "POC"}, {"AEK", "THJ"}, {"AFO", "EUP"},
{"AHB", "HYW"}, {"AIB", "GFW"}, {"AJX", "BUX"},…

jnnnnn
- 3,889
- 32
- 37
1
vote
1 answer
What happens if an exception occur before than static local variables are initialized?
When are static local variables initialized?
If an exception is thrown in a constructor, is the object considered constructed? Will the destructor be called?
consider fallowing code :
#include
#include
int x = 0;
class A…

Adib
- 723
- 5
- 22
1
vote
4 answers
Creating a statically allocated array from two other arrays
Let's say I have two statically allocated global arrays:
const int foo[] = {1, 2, 3};
const int bar[] = {4, 5, 6, 7};
Later on the same compilation unit I'd like to declare an array that is also statically allocated and is the concatenation of foo…

BeeOnRope
- 60,350
- 16
- 207
- 386
1
vote
1 answer
How to define constant arrays of dim3 structs in CUDA
I am writing some CUDA code to run on the device. The code will use two lookup tables of constant values. The first of these is an array of 256 unsigned ints and I declare it as :
__constant__
uint16_t edgeTable[256]={
0x000,
0x019,
...…

Dave Durbin
- 3,562
- 23
- 33
1
vote
2 answers
How to initialise an array of N function pointers to function templates indexed from 0..N-1?
Given a function pointer array of function_sig, I want to initialise it to a set of template function pointers that are index via a template parameter. Is this possible?
E.g.
template
void fn() { /* do something */ }
typedef…

Adrian
- 10,246
- 4
- 44
- 110
1
vote
3 answers
Java - static initializers in imported projects
So I have two projects A and B, and project B is imported in project A, and in project B I want to initialize some objects which have static initializers.
The problem is, they aren't getting called (already tested with final keyword, does not…

Milixyron
- 105
- 2
- 9
1
vote
0 answers
Is there a way for a class to trigger it's own classloading without being on the path of execution of a program?
I get that you can run a method on classloading by using a static initializer.
The challenge is waiting for the classloader to load the class.
Assume my class to load is Initializer. (No package).
You can trigger the classloader to load the class…

hawkeye
- 34,745
- 30
- 150
- 304
1
vote
1 answer
Order of class initialization during java deserialization
During deserialization, are subclasses guaranteed to be initialized before any class instance objects are restored from the input stream? Specifically, I have a subclass with static fields that I'd like to access in the superclass readObject()…

ags
- 719
- 7
- 23
1
vote
1 answer
Using a variable from a different file before main
I'm having a little trouble understanding why my code works the way it does (or doesn't work the way it ought to).
I'm trying to write (in C++) an interface that allows to use some functions operating on unordered_map from the standard template…

Jytug
- 1,072
- 2
- 11
- 29
1
vote
2 answers
Ada initialization of controlled singleton variable
I am trying to create a package with a singleton variable that is auto initialized. If the singleton variable is not a controlled type, then the compiler doesn't complain, but when I make it controlled, I get the warning:"cannot call Initialize…

Victor
- 35
- 4
1
vote
1 answer
Initializing chosen elements of std::map to the same value at compile time
Suppose I have the following piece of code:
#include
using namespace std;
class SomeClass {
private:
const static map some_map;
};
const map SomeClass::some_map = {
{1, 2},
{3, 2},
{4, 2},
…

syntagma
- 23,346
- 16
- 78
- 134