Questions regarding initialization code of static members
Questions tagged [static-initialization]
325 questions
-1
votes
1 answer
static initializer block return void
I know that it isnt about my problem but just to you know, this is my first stackoverflow post and yes, my english isnt quite good so please, i sincerely ask you guys, be patience. I'd chosen english community because brazillian stack overflow…

FARS
- 313
- 6
- 20
-1
votes
3 answers
What is true reason for initiliazing need of final varibles before use
I know that:
A blank final class variable must be definitely assigned by a static initializer of the class in which it is declared, or a compile-time error occurs.
A blank final instance variable must be definitely assigned at the end of…

Yarl
- 728
- 1
- 7
- 26
-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…

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…

infoholic_anonymous
- 969
- 3
- 12
- 34
-2
votes
1 answer
c++ initial value of global array declarer vs initial value of local function array declarer
#include
using namespace std;
int a[100]; // <--
int main() {
for (int i = 0; i < 100; i++) {
cout << a[i] << " ";
}
return 0;
}
After declaring the array globally in the above code, all the indices…

Asif_102
- 53
- 5
-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…

João Pires
- 927
- 1
- 5
- 16
-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…

jww
- 97,681
- 90
- 411
- 885
-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…

St.Antario
- 26,175
- 41
- 130
- 318
-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…

user6363174
- 13
- 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…

tSchema
- 193
- 2
- 12