Error: constant false is not an lvalue

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Aug 29 21:53:22 PDT 2009


On Sun, Aug 30, 2009 at 12:24 AM, Ary Borenszweig<ary at esperanto.org.ar> wrote:
> Steven Schveighoffer escribió:
>>
>> On Sat, 29 Aug 2009 20:15:55 -0400, Ellery Newcomer
>> <ellery-newcomer at utulsa.edu> wrote:
>>
>>> void blah(out bool a = false){
>>>  // blah blah blah
>>> }
>>>
>>> compile time use of blah results in error.
>>>
>>> Am I doing anything wrong?
>>
>> out implies a reference.  You can't have a reference to a manifest
>> constant like that.
>>
>> If you want to ensure a is false at the beginning of the function do:
>>
>> void blah(out bool a)
>> {
>>  a = false;
>>  // blah blah blah
>> }
>>
>> -Steve
>
> Or just not write it, because "out" automatically initializes the value of
> the variable to it's default one, in the case of bool it's false.

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.

But we're getting really technical here ;)


More information about the Digitalmars-d-learn mailing list