[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pnet-developers] [bug #15345] strings created in a while loop are n
From: |
Marcus |
Subject: |
Re: [Pnet-developers] [bug #15345] strings created in a while loop are not made null each iteration |
Date: |
Sun, 1 Jan 2006 00:00:49 -0600 |
User-agent: |
KMail/1.9.1 |
The code given is not legal C#, so the behavior of the code is not undefined.
Specifically, the local variable "test" is not definitely assigned prior to
its use. Unfortunately, cscc does not perform definite assignment analysis.
(I am pretty sure that this has been reported before because it is a known
issue.)
Nevertheless, when I compiled the code with cscc and then run it under Pnet,
Mono, and MS, I got the same results.
> <http://savannah.gnu.org/bugs/?func=detailitem&item_id=15345>
> Strings (and probably every other type) created in a while loop are not
> made null each iteration. Instead, their value is preserved across
> iterations. I don't claim to be a C# expert, but it is my understanding
> that they should be made null each iteration.
>
> Consider the following code:
>
> public class adsf {
> static void Main() {
> int a=0;
> while (a<=3) {
> string test;
> test += a.ToString();
> Console.WriteLine("{0}", test);
> a++;
> }
> }
> }
>
> This compiles fine with cscc, and gives this output:
> 0
> 01
> 012
> 0123
>
> As you can see, the value of the string "test" is preserved across
> iterations. csc or mcs both refuse to compile this code unless the line is
> changed to: string test = ""
>
> Regardless of whether or not cscc lets it compile, I believe that the
> string should be set to null every iteration.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Pnet-developers] [bug #15345] strings created in a while loop are not made null each iteration,
Marcus <=