Questions tagged [static-initialization]

Questions regarding initialization code of static members

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…
-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…
-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
  • 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…
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…
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…
-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…
1 2 3
19
20