Questions regarding initialization code of static members
Questions tagged [static-initialization]
292 questions
-1
votes
1 answer
Is it deadlock? Why it happens?
Can someone explain to me why the following code prints nothing?
When I tried to debug it, the debugger froze on the line t.join();. But in the debugger I saw the message: "program is running".
public class Main_problem1_multithreading {
private…
![](../../users/profiles/2443298.webp)
Anton
- 5
- 2
-1
votes
2 answers
static members and encapsulation in c++
Let us assume the following class:
class FileManipulator
{
static InputTypeOne * const fileone;
InputTypeTwo *filetwo;
public:
FileManipulator( InputTypeTwo *filetwo )
{
this->filetwo = filetwo;
}
int…
![](../../users/profiles/1342976.webp)
infoholic_anonymous
- 929
- 3
- 12
- 29
-2
votes
3 answers
C dummy struct, strict aliasing and static initialization
My first question wasn't well formulated so here goes again, this time, more well asked and explained.
I want to hide the variables of a struct while being able to initialize the struct statically on the stack. Most solutions out there use the…
![](../../users/profiles/7198015.webp)
João Pires
- 803
- 5
- 14
-2
votes
1 answer
Force variable in source file into initialized data segment on OS X?
I have a bool type in a CPP source file. The variable cannot be made static. I want the variable placed in an initialized data segment.
According to the OS X ABI Mach-O File Format Reference, I believe the place I want the variable to reside is…
![](../../users/profiles/608639.webp)
jww
- 83,594
- 69
- 338
- 732
-2
votes
2 answers
Understanding static initialization
I wrote this code:
#include
#include
#include
constexpr int foo(int a, int b)
{
return a*b;
}
int bar(int a, int b)
{
return a*b;
}
int a = bar(1,2); // Dynamic initialization. This brace-or-equal…
![](../../users/profiles/2786156.webp)
St.Antario
- 23,179
- 26
- 96
- 243
-4
votes
2 answers
Static const without initializer
In C you can do this:
static const int a;
int main(){}
And it seems to be fine. C99 §6.7.8p10 says:
If an object that has static storage duration is not initialized
explicitly, then:
— if it has arithmetic type, it is initialized to (positive…
![](../../users/profiles/6363174.webp)
user6363174
- 3
- 1
-4
votes
1 answer
When to use initializers?
I recently came across the following bit of java syntax:
static {
...
}
apparently this is known as a "static initializer" (see Static Block in Java) and is "executed when the class is loaded".
When should a static initializer be used? What are…
![](../../users/profiles/1470672.webp)
tSchema
- 161
- 2
- 9