Invalid c# Compiler Behaviour !?

Discussion in 'MCSD' started by Disillusioned_01, May 28, 2004.

  1. Code Below produces

    invalid2cs.txt(22,8): error CS0165: Use of unassigned local variable 'a'

    I believe this is wrong ....

    Also this code is not working in Visualstudio 2002 /Framework ver.1.0
    (Invalid program exception with no Source)

    Butworks with .net 1.1 ...

    Any explanations will be much appreciated...

    (Obviously any body done a compiler can see this is probably wrong)

    Code

    using System;

    using System.Text;


    namespace working_with_text

    { {


    [STAThread]

    static void Main(string[] args)

    { char c, ch;

    c=(char) System.Console.Read();

    ch=(char) System.Console.Read();

    Int32 a,b; goto c1;

    a1: if (a.Equals(b)) Console.WriteLine("a==b");goto b1;

    c1: if ( c == ch) a = 32;

    b = a; goto a1;

    b1: Console.WriteLine("Finished");}}

    }
     
    Disillusioned_01, May 28, 2004
    #1
    1. Advertisements

  2. I apologize for my rambling . I nearly forgot that they can't
    write good compilers ...
     
    Disillusioned_01, May 28, 2004
    #2
    1. Advertisements

  3. Disillusioned_01

    Me2 Guest

    Hello Disill,

    I hope they have better programmers in Auckland than yourself.

    If you don't like the compiler, go use someone else's.

    I can guarantee you that they have not used even one goto in the compiler.
    Maybe from your stand point that is the problem.

    Either I am just baffled by your grasp of programming, or your logic is way
    off in space. You need to start with some basic principles of structured
    programming texts.

    Sorry if this isn't what you wanted to hear, but you need to improve your
    base programming knowledge.

    --
    Ralph Page MBA, CMBA, MCDBA, MCSE, CCNA
    -------------------------------------------------------------------------
    "However beautiful the strategy, you should occasionally look at the
    results."
    -- Winston Churchill
    -------------------------------------------------------------------------
     
    Me2, May 28, 2004
    #3
  4. Thanx.
    I was trying ot break csc compiler
    I was actually questioning the statement that
    'uninitialised variables can't be used.....etc''
    Please check link below ...
    http://www.dotnet247.com/247reference/msgs/24/123945.aspx

    I know it is quite painful to admit that csc compiler can't construct
    correct IL for a simple program especially micosoft is your bread.
    Peace
    :)

     
    Disillusioned_01, May 28, 2004
    #4
  5. Disillusioned_01

    UAError Guest

    using System;
    using System.Text;

    namespace working_with_text{
    {
    [STAThread]
    static void Main(string[] args){
    // Entry point
    char c, ch;
    //(1) assign first character
    c=(char) System.Console.Read();
    //(2) assign second character
    ch=(char) System.Console.Read();
    // (3) skip forward to label c1
    Int32 a,b; goto c1;

    a1: if (a.Equals(b))
    Console.WriteLine("a==b");

    goto b1;

    // (4) 'a' is only assigned if 'c == ch'
    c1: if ( c == ch) a = 32;
    // (5) 'a' is unassigned if 'c != ch'
    b = a; goto a1;
    b1: Console.WriteLine("Finished");
    }
    }
    }

    so the compiler is well within its rights to complain
    the only improvement to the error message might be

    Use of POTENTIALLY unassigned local variable 'a'

    I doubt however that would have made any difference


    Almost anyone can write code that that is understood by a
    computer but it is more important that the code is easily
    grasped by most programmers of varying competence.

    When you write code always imagine that the person that has
    to maintain your code is an unstable psycho mass-murder who
    knows where you live.
     
    UAError, May 28, 2004
    #5
  6. When you write code always imagine that the person that has
    You missed an important point....

    Code is written to implement a chosen design which solves a business
    problem. As such, the code should be able to be traced back to that
    business problem.

    In addition, good coding standards would never allow that type of
    'code' to become a configuration item.

    Kline Sphere (Chalk) MCNGP #3
     
    The Poster Formerly Known as Kline Sphere, May 28, 2004
    #6
  7. I agree with you. You won't write such code for even your
    uni assinment .
    But All I want to point out is there are
    some erraneous compiler behaviour with csc.exe in .net 1.0 sdk
    Which I later found out that it is fixed in .net 1.1 .
    But I am quite happy that in the end CLR IL verifier caught it though., Good
    programming model ,but I could have done without an
    Invalid program exception and makes me suspiscious of the amount of testing
    done on this compiler itself.
     
    Disillusioned_01, May 29, 2004
    #7
  8. by the way
    look at shared source implementation
    \sscli_20021101\sscli\ compiler.cpp uses goto statements + whole lot of
    other files used to make csc.exe hehehe
     
    Disillusioned_01, May 29, 2004
    #8
  9. I agree with you. You won't write such code for even your
    unless you wished to fail!
    There are always ways to 'trick' a compiler into doing stupid things,
    like casting away constness in C++. My point is not to try and do
    stupid things, hence my point on coding procedures/practices and
    reviews.

    My view is that for such errors, a compile should simply turn the
    volume up and yell out 'YOU'RE AN IDIOT!!!!'

    Kline Sphere (Chalk) MCNGP #3
     
    The Poster Formerly Known as Kline Sphere, May 29, 2004
    #9
  10. Umm... Kline Sphere Original...
     
    Disillusioned_01, May 29, 2004
    #10
  11. meaning?


    Kline Sphere (Chalk) MCNGP #3
     
    The Poster Formerly Known as Kline Sphere, May 29, 2004
    #11
  12. Well......Just pointing out that I loved your argument ...
    Now Goback to your Cofee
     
    Disillusioned_01, May 29, 2004
    #12
  13. Well......Just pointing out that I loved your argument ...
    ....and Pizza! Just eat the whole damn lot!!!

    Kline Sphere (Chalk) MCNGP #3
     
    The Poster Formerly Known as Kline Sphere, May 29, 2004
    #13
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.