Error: constant false is not an lvalue
Rainer Deyke
rainerd at eldwood.com
Sun Aug 30 02:34:45 PDT 2009
Jarrett Billingsley wrote:
> Although teeeeeeechnically speaking that would be illegal code. The D
> spec says that it's not legal to use the value of uninitialized
> variables. Default initialization is kind of a poor man's substitute
> for actual flow control which determines that. By relying on default
> initialization, you're relying on what is actually nonconformant
> behavior, and it could be broken in the future or by a smarter
> compiler.
No. This is an uninitialized variable in D:
int i = void;
This is an initialized variable in D:
int i;
A default-initialized variable is not in any way less initialized than
any other initialized variable.
Flow control can add two things to D. It can turn this:
int i = <value>;
or, equivalently, this:
int i;
into this:
int i = void;
whenever it is safe to do so. It can also turn this:
int i = void;
into an error message if it can prove that this is /not/ safe.
It cannot ever alter the behavior of the following perfectly legal D
function:
int get_zero() {
int i;
return i;
}
--
Rainer Deyke - rainerd at eldwood.com
More information about the Digitalmars-d-learn
mailing list