bugDotGNU Portable.NET - Bugs: bug #19129, Reading uninitialised variable...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #19129: Reading uninitialised variable does not cause compile error.

Submitter:  None
Submitted:  Fri 23 Feb 2007 01:43:13 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Sat 24 Feb 2007 02:04:58 AM UTC, comment #3: 

Hello,

I see your point. Semantics are still defined for uninitialized variables and therefore the code is correct seen from the compilers point of view, and soundness is preserved.

However, I do not agree that "my code will work". How should the compiler know which value I need my variables to be initialized with? The original error message was helping the programmer.

Robert Jørgensgaard Olesen <egir>
Fri 23 Feb 2007 02:59:36 PM UTC, comment #2: 

Hello,
i can confirm this from my experience. I guess that checking for unitialized values is not implemented in cscc compiler, but the resulting code is correct (all variables in C# are internally always initialized to the default value which is 0 in this case.)

You can safely use cscc even if it does not print these warnings. Your code will work, but you will have to correct your code to compile with other C# compilers then (which is not really big problem).

Radek Polak <radekp>
Group Member
Fri 23 Feb 2007 02:54:58 PM UTC, comment #1: 

This violates the soundness of the C# type system.

Robert Jørgensgaard Olesen <egir>
Fri 23 Feb 2007 01:43:13 PM UTC, original submission:  

Reading uninitialised variable does not cause compile error. I was reading "Programming C#" from Oreley. Example3-2 on page 27 is an example of using an unitialised variable, see attachment. According to "Programming C#" I am suposed to get this error message when compiling:

3.1.cs(6,55): error CS0165: Use of unassigned local
variable 'myInt'

But cscc version 0.7.4 compiles without any error, and the program runs without crashing:

$ cscc Values.cs
$ ilrun a.out
Uninitialized, myInt: 0
Assigned, myInt: 5

According to "Programming C#" it is not legal to use an unitialised variable in C#.

Example3-2 is attached as Value.cs.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #12030:  Values.cs added by None (252B - text/x-csharp - Example3-2 from "Programming C#")

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by radekp (Posted a comment)
  • -email is unavailable- added by egir (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-02-23 egir Carbon-Copy- Added egir
    2007-02-23 None Attached File- Added Values.cs, #12030

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code