initialization

C - Change all values of an array of structures in one line

I can declare a structure: typedef struct { int var1; int var2; int var3; } test_t; Then create an array of those structs structure with default values: test_t theTest[2] = { {1,2,3}, {4,5,6} }; But after I've created the array, is there any way to change the values in the same way I did above, using only one line, spec...

When is my C# property initialized?

I'm a little confused about when exactly my Property is being initialized. Suppose I have a property declared like this: private Dictionary<string, Dictionary<string,string>> MessageLookup { get { return messages ?? doSomething(); } } The doSomething method populates the messages Dictionary ...

Determine static initialization order after compilation?

In C++, I know that the compiler can choose to initialize static objects in any order that it chooses (subject to a few constraints), and that in general you cannot choose or determine the static initialization order. However, once a program has been compiled, the compiler has to have made a decision about what order to initialize these...

C - Check if Integer is assigned

Hi, How do I determine if an integer is unassigned? int i; /* no assignment */ if (/* conditional statement here to check if int i is unassigned or not */) { printf("Integer is unassigned!\n"); } else { printf("Integer is assigned!\n"); } Language: C Best regards, Timothy ...

How lazy can C++ global initialization be?

I'm used to thinking of all initialization of globals/static-class-members as happening before the first line of main(). But I recently read somewhere that the standard allows initialization to happen later to "assist with dynamic loading of modules." I could see this being true when dynamic linking: I wouldn't expect a global initialize...

NSDate init question, related to memory management in Objective-C

I have an NSDate object created by NSDate *date = [[NSDate alloc] init]; Later, I want to reset the date to the "now", so I thought that [date init]; or date = [date init]; might do the job, but they don't. Instead, [date release]; date = [[NSDate alloc] init]; works. I'm a bit confused about this, since in the documentation ...

Reflectively accessing a static variable in a Java class

I've been given no other choice but to access a set of classes, which I cannot modify, with this structure through reflection. Using the method shown in the main method below however, throws a NullPointerException. The null pointer being "table" in the constructor when f1.get(null) is called. I am unable to instantiate the classes befo...

log4net initialisation

I've looked hard for duplicates but have to ask the following, no matter how basic it may seem, to get it clear once and for all! In a fresh Console app using log4net version 1.2.10.0 on VS28KSP1 on 64 bit W7, I have the following code:- using log4net; using log4net.Config; namespace ConsoleApplication1 { class Program { ...

Returning object initialized through "convenience constructor"

When an instance method returns a value that was initialized with a convenience constructor, do I need to retain that object and then autorelease in the return so that when the convenience constructor's autorelease occurs, it doesn't remove the object. Will this release description before the calling code and take ownership with a retai...

Are function static variables thread-safe in GCC ?

In the example code void foo() { static Bar b; ... } compiled with GCC is it guaranteed that b will be created and initialized in a thread-safe manner ? In gcc's man page, found the -fno-threadsafe-statics command line option: Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initiali...

Should I set the initial java String values from null to ""?

Often I have a class as such: public class Foo { private String field1; private String field2; // etc etc etc } This makes the initial values of field1 and field2 equal to null. Would it be better to have all my String class fields as follows? public class Foo { private String field1 = ""; private String field2 = ""; // etc etc et...

Valid use of accessors in init and dealloc methods?

I've heard now from several sources (stackoverflow.com, cocoa-dev, the documentation, blogs, etc) that it is "wrong" to use accessors and settings (foo, setFoo:) in your init and dealloc methods. I understand that there is there is a remote possibility of confusing other objects that are observing the property if you do so. (a simple e...

iPhone dev - create array in init or viewDidLoad

In my UIViewController subclass should I initialize the NSArray of data for the UIPickerView in init or in viewDidLoad and why? Thanks. ...

Question about NSMutableArray

Hi I currently try to fill and NSMutableArray with something like this: deck = [[NSMutableArray alloc] initWithCapacity:52]; for (int suit = 0; suit <= 3; suit++) { for (int value = 1; value <= 13; value++) { ANormalCard *card = [[ANormalCard alloc] initWithSuit:suit value:value]; [deck addObject:card]; [card autorelease...

Why might a static data member not get initialized?

I'm trying to register a bunch of classes with a factory at load time. My strategy is to harness static initialization to make sure that before main() begins, the factory is ready to go. This strategy seems to work when I link my library dynamically, but not when I link statically; when I link statically, only some of my static data me...

Why does a variable turn null after initialized in the Page_Init?

I define an array in in the class, not in any method, as a global variable, in the same scope of method: TextBox[,] tx = new TextBox[100,100]; TableCell[,] tc = new TableCell[100, 100]; TableRow[] tr = new TableRow[100]; And I initialize them in Page_Init event: protected void Page_Init(object sender, EventArgs e) { if (!...

newbie: C++ question about initialization lists

Hi all, Let's say I have an array of objects declared in my header. The size of the array could be very large. In my source file, I create the constructor for my class and I'd like to initialize all the objects in my array. If these objects are not being constructed with a zero-parameter constructor, I am told these need to be put in...

Cocoa - Singleton object: Where to initialize member variables?

Hello people! I was wondering where is the best place to initialize members of the singleton class. I'm using Apple fundamental guide singleton implementation. Could you please pinpoint at what line the inits happen? The code is the following: static MyGizmoClass *sharedGizmoManager = nil; + (MyGizmoClass*)sharedManager { @synchr...

Objective-C class instance zeroed at alloc?

Is there any kind of memory-zeroing objective-c undertakes on my behalf when I first allocate a class instance? I see a lot of objective-c code out there that presumes their outlets are nil by default. If I do the same am I basing such behavior on false pretenses? ...

How do I initialise a global array of structs in D?

In aid of my one-man quest to populate SO with D questions (=p), I've run into another problem; initialising an array of structs globally. Observe: struct A { int a; float b; } A[2] as; as[0] = {0, 0.0f}; as[1] = {5, 5.2f}; void main() {} Results in: $ dmd wtf.d wtf.d(8): no identifier for declarator as[0] wtf.d(9): no ide...