int nan
Michiel Helvensteijn
m.helvensteijn.remove at gmail.com
Sat Jun 27 08:59:52 PDT 2009
Denis Koroskin wrote:
>> int i;
>>
>> for(int j = foo(); j > 0; j--) i = bar(j); // what if foo() returns
>> -5?
>
> This code doesn't compile in C# and fails with the following error at
> first attempt to use 'i':
>
> error CS0165: Use of unassigned local variable 'i'
Ah, so C# is overly conservative. That's another option, of course.
It has the advantage of always knowing at compile time that you're not
reading an uninitialized value. The disadvantage is that C# will often
throw out the baby with the bath water. The example program may be
perfectly valid if 'foo' always returns positive.
--
Michiel Helvensteijn
More information about the Digitalmars-d
mailing list