Compilation Error :Reasoning:

Discussion in 'C' started by shwetank, Oct 7, 2010.

  1. shwetank

    shwetank New Member

    Joined:
    Oct 7, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    ------

    int x,x;
    int main(){
    int x,x;
    x = 10;
    return 0;
    }

    In this code ... if i commented out the local declaration of "int x,x;" (inside main) the code compiling successfuly..
    But if commented out global ones and not local one's we will get compilation error for the same variables name declaration...
    Can sb let me know the resoning behind the same.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Probably a compiler bug. The error message is correct and you should get it for both faulty declarations. What compiler are you using?
     
  3. shwetank

    shwetank New Member

    Joined:
    Oct 7, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I tried it on GCC and CC on linux(suse):embarasse
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What version?
     
  5. shwetank

    shwetank New Member

    Joined:
    Oct 7, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Its a default one...
    Have u tried the same code in ur C compiler
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    That completely doesn't answer the question.

    Why would I need to? It's invalid code. Anyway, since you can't be arsed to find out how to make gcc print its version, I can't be arsed either.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice