initialization

How to initialise a C program using file, environment and/or command line?

In C, how to configure the initial settings for some program, using key-value pairs, with any or all of: a plain text configuration file, environment variables, and options on the command line. Also, how to decide which method's values overide those from either of the other two. Then if values have been changed, to optionally update the ...

VB6.0 : initialize method of a User Control called when loading a VB project.

Whenever we load a VB project it will call initialize method of a User Control ( if there is any in the project). My problem is that is that I have some code in UserControl.initialize that will try to create instances of other COM objects. And on my build machine those controls are not registered. One option is to move the code to some o...

C# 3.0, object initializer and get property returning array, how to initialize?

Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass() { _someThings = new int[4]; } public int[] SomeThings { get { return _someThings; } } } How would I use the object initializer syntax to initialize the SomeThings property like in th...

Which variables are initialized when in Delphi?

So I always heard that class fields (heap based) were initialized, but stack based variables were not. I also heard that record members (also being stack based) were also not initialized. The compiler warns that local variables are not initialized ([DCC Warning] W1036 Variable 'x' might not have been initialized), but does not warn for...

Python Class Members Initialization

Hello, I have just recently battled a bug in Python. It was one of those silly newbie bugs, but it got me thinking about the mechanisms of Python (I'm a long time C++ programmer, new to Python). I will lay out the buggy code and explain what I did to fix it, and then I have a couple of questions... The scenario: I have a class called A...

manual initialization of required Hibernate database tables

I'm getting started in Hibernate and so far it's not too hard. But I am confused about the hbm2ddl.auto property. Is there a way to manually execute whatever this does to initialize the database tables? I only want to do this after I make my database changes, not every time I run my program. edit: what about at runtime? is there a way i...

Should Constructor initialize own parameters directly to the private member or via the public field ( C# centric)?

E.g. which way is better class Foo { private string _Bar ; Foo ( string bar) { _Bar = bar ; } public string Bar { get { return _Bar ; //more logic here } set { _Bar = value ; //more logic could be added } } } OR class Foo { private string _Bar ; Foo ( string bar) { this.Bar = bar ; } publ...

How is static variable initialization implemented by the compiler?

I'm curious about the underlying implementation of static variables within a function. If I declare a static variable of a fundamental type (char, int, double, etc.), and give it an initial value, I imagine that the compiler simply sets the value of that variable at the very beginning of the program before main() is called: void SomeFu...

Initializing pointers in C++

Can assign a pointer to a value on declaration? Something like this: int * p = &(1000) ...

What does this C error about structures mean?

Hey everyone! Could someone please help me understand this error in C for structures? This is my code: struct Orientation { char facing; char sensor; char mazeDir; }; struct Orientation O[16]; O[0] = {'N', 'F', 'N'}; O[1] = {'N', 'B', 'S'}; O[2] = {'N', 'R', 'E'}; O[3] = {'N', 'L', 'W'}; O[4] = {'S', 'F', 'S'}; O[5] = {'S'...

Initializing an object with references without accessing a non-default constructor

Let's suppose I have an interface named "Controller". Several classes implement this interface and I don't know these classes (e.g. the class names are located in an xml-file). Now for this Controller-implementing classes to work they have to get some references to other objects (maybe data objects). And this is my question, namely what ...

c# [NonSerialized] field with inline initialization isn't initialized after deserialization

I have a [Nonserialized] field in my class that is initialized inline: [NonSerialized] private bool running = true; However, after deserializing an object I have running == false. This is not what I want. Can I force inline initializatin to work for all [NonSerialized] fields? Otherwise I will have to implement ISerializable... ...

Why do some const variables referring to some exported const variables get the value 0?

Consider the following. I have two exported constants as follows: // somefile.h extern const double cMyConstDouble; extern const double cMyConstDouble2; and // somefile.cpp const double cMyConstDouble = 3.14; const double cMyConstDouble2 = 2.5*cMyConstDouble; These constants are now referenced some place else to define two static (...

Efficiency of Java "Double Brace Initialization"?

In Hidden Features of Java the top answer mentions Double Brace Initialization, with a very enticing syntax: Set<String> flavors = new HashSet<String>() {{ add("vanilla"); add("strawberry"); add("chocolate"); add("butter pecan"); }}; This idiom creates an anonymous inner class with just an instance initializer in it, w...

Learning Ajax - where to search for online instruction.

Hello everybody. I have good knowledge in Php, Mysql, and with Stack Overflow users help i started understanding a bit more of Javascript. Which by the way thanks for all those who have helped so far. I always want learn a bit more, and I always had a little admiration for Ajax, and once in Ajax i can use Php and MySql... So i wanted ...

Objective C two-phase construction of objects

I've been reading up on RAII and single vs. two-phase construction/initialization. For whatever reason, I was in the two-phase camp up until recently, because at some point I must have heard that it's bad to do error-prone operations in your constructor. However, I think I'm now convinced that single-phase is preferable, based on quest...

How can I perform pre-main initialization in C/C++ with avr-gcc?

In order to ensure that some initialization code runs before main (using Arduino/avr-gcc) I have code such as the following: class Init { public: Init() { initialize(); } }; Init init; Ideally I'd like to be able to simply write: initialize(); but this doesn't compile... Is there a less verbose way to achieve the same effect?...

C# Variable Initialization Question

Good Day, Is there any difference on whether I initialize an integer variable like: int i = 0; int i; Does the compiler or CLR treat this as the same thing? IIRC, I think they're both treated as the same thing, but I can't seem to find the article. coson ...

How can I detect if a Java class is called by its own main() or from another class?

I have a Java class that looks like this: public class My_ABC { int a=0; boolean B=true; static // Initialize and load existing data only once at start-up { // need to know if it's called from its own main() // or by another class to conditionally set veriables } public My_ABC(int AA,boolean BB) { } publ...

Variable initialising and constructors

I am currently taking a c++ course and trying to get a deep understanding of the whole thing. I came up with some theories, it would be great if somebody could confirm them: Every variable (local,global,staic,member and non-member) is guaranteed to have its ctor called before first use The ctors of primitives like int are essentially n...