Error: constant false is not an lvalue

grauzone none at example.net
Sun Aug 30 04:13:01 PDT 2009


Jarrett Billingsley wrote:
> 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

Am I the only one, who likes the current behaviour, and finds it 
annoying to be forced by the compiler to initialize all variables?

> initialization, you're relying on what is actually nonconformant
> behavior, and it could be broken in the future or by a smarter
> compiler.

How is this nonconformant? Initialization is guaranteed by D.

> But we're getting really technical here ;)


More information about the Digitalmars-d-learn mailing list