What is the stance on partial initializers when declaring multiple variables of the same type?

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Jul 20 23:52:03 PDT 2011


I ran into this simple C declaration:

float float_x, float_y, float_xb, float_yb;

These need to be explicitly initialized in D, otherwise you either get
crashes or you won't get anything but a blank screen (with regards to
rendering with OpenGL).

Almost instinctively I went for:

float float_x, float_y, float_xb, float_yb = 0.0;

But that's incorrect, only float_yb is zero-initialized, the others
are initialized to NaN (well I predicted that but I was kinda hoping D
would be cool and use a common initializer).

What I'm asking is, are partial initializers useful for people? I'm
not suggesting any changes, but just starting a discussion. It does
look like this could maybe introduce bugs. I think someone might have
mentioned this topic before, but I don't recall.

Here's to a healthy discussion..


More information about the Digitalmars-d mailing list