Questions regarding initialization code of static members
Questions tagged [static-initialization]
325 questions
0
votes
2 answers
VBA Error: How do I define and initialize an Array in VBA
I copied this code from Microsoft, but it does not work.
Dim Pixels(1 To 3) As Integer
Pixels = Array(1, 2, 3)
When I excute it, I get an error on the '1' in the Array Statement
saying "Invalid outside procedure".
I am running the code from an…

Lingo
- 1
- 3
0
votes
1 answer
Constexpr constructor for a static variable results in dynamic initialization
I have the following program:
#include
void Init();
struct Foo {
Foo() {
int *p = new int; // just to make sure Foo's ctor is not a constant expression
Init();
}
} foo;
struct Bar {
constexpr Bar()
:…

undermind
- 1,779
- 13
- 33
0
votes
1 answer
How to Stop static initialization with PowerMockito
I am working on an API for work, we use a shared library for multiple projects for the purposing of our logging framework. The class used uses all static methods for its calls.
I am trying to Unit test an API call, I can not have it call anything on…

needoriginalname
- 703
- 3
- 9
- 27
0
votes
1 answer
Find functions names in .init_array section in unstripped library
Is it possible to find out all instances of static initialization in a elf dynamic library. I can dump the array of function pointers in .init_array section via objdump command like this.
objdump -s -j .init_array
Is there a way to…

Arpit Aggarwal
- 841
- 8
- 18
0
votes
0 answers
Linking: how to force include of .obj / .cpp file or why is it excluded from build?
I have a peculiar case where some static-initialization code in a .cpp file that is not actually used by the rest of the project seems to be excluded from the build. However, the static-initialization is important enough. Is there some way - short…

darune
- 10,480
- 2
- 24
- 62
0
votes
2 answers
Static array of static members: possibility of initialization order fiasco
Consider the following code:
class Foo {
public:
static const char one[];
static const char two[];
static const char* all[];
};
const char Foo::one[] = "one";
const char Foo::two[] = "two";
const char* Foo::all[] = {Foo::one,…

Petr
- 9,812
- 1
- 28
- 52
0
votes
1 answer
Global variable initialization order
One issue of global variables is that initialization order is undefined across translation units, and we have some practices to avoid the global variables. But I still want to understand the initialization order of global variables across…

zhihuifan
- 1,093
- 2
- 16
- 30
0
votes
1 answer
How can I initialize a class that was dynamically loaded with a custom class loader?
Suppose I have a class that is loaded using a custom class loader
Class> clz = myClassLoader.loadClass("classLoaders.Test");
How can I initialize the class (run its static initializers) without creating an instance, knowing its members, or using…

Gonen I
- 5,576
- 1
- 29
- 60
0
votes
1 answer
Is it a good practice to use static initializers?
Is there any alternative to static initializers in Java?
Just a random example:
private static List list;
static {
list = new ArrayList<>();
list.add("foo")
}
Doesn't it make debugging harder?

Mahozad
- 18,032
- 13
- 118
- 133
0
votes
2 answers
Error in static initialization of array of integer pointers in C
I am getting an error in initialization of array of integer pointer. Though the issue seems simple I am unable to understand what's wrong in this.
I am new in C programming.

Monalisa Das
- 667
- 5
- 3
0
votes
1 answer
Threads not coming to a halt even when trying to acquire the same lock from the JVM static initialization process
In the Java Concurrency in Practice book, it says that
"Static initializers are run by the JVM at class initialization time, after class loading
but before the class is used by any thread. Because the JVM acquires a lock during initialization…

katiex7
- 863
- 12
- 23
0
votes
1 answer
Initialization of static members of class templates with side effects
My C++14 application needs to dynamically create and destroy objects of a certain type. Each of these objects is named, and the name is assigned when the object is constructed. Each name is hard-coded as a string literal. The following pseudocode…

Pavel Kirienko
- 1,162
- 1
- 15
- 31
0
votes
1 answer
Initialize a static const member with a template argument
I have a few lines that compile well on my system but don't compile on a colleagues system. That's why I would like to ask what the go-to solution for the problem would look like. I have to deal with a enum that implicitly defines how much space I…

ruhig brauner
- 943
- 1
- 13
- 35
0
votes
2 answers
Is there a way to create a static const class value that is initialized with a loop?
A static member may be declared const, but then it must be initialized in the declaration. Consider the following case of a static array to be initialized with code in loops:
class A {
private:
enum { SIZE = 360 };
static double*…

Dov
- 8,000
- 8
- 46
- 75
0
votes
3 answers
Static initialization order issue in C++
This is another variation of an old theme: The initialization order of
static objects in different translation units is not defined.
Below is a stripped-down example of my particular scenario. The
classes G and F are non-POD types. F depends on G is…

cj.
- 250
- 1
- 3
- 13