detecting errors with the compiler

This is a discussion on detecting errors with the compiler within the C++ Programming forums, part of the General Programming Boards category; how come when i have Code: int myFunc(unsigned short int x); the compiler will give me an error about the ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    494

    detecting errors with the compiler

    how come when i have
    Code:
    int myFunc(unsigned short int x);
    the compiler will give me an error about the semicolon at the end of the function definition but when i click to see at what line the error is, it doesnt give me the exact line, instead it gives the line below that which is only a }, u know what i mean?

    so the compiler doesnt always detect the error where the error occurs? why does this happen?
    When no one helps you out. Call google();

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    when you are defining a function, you omit the semicolon:
    Code:
    void foo()
    {
          //blah
    }
    only when you call the function, or set its prototype do you include the ";"
    Last edited by axon; 04-22-2004 at 09:03 PM.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it gives you the line below, because like axon said, that line of code is perfectly legal... it just happens to make the following lines illegal...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Quote Originally Posted by major_small
    it just happens to make the following lines illegal...
    thats makes sense cool.
    When no one helps you out. Call google();

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    the compiler will give me an error about the semicolon at the end of the function definition but when i click to see at what line the error is, it doesnt give me the exact line, instead it gives the line below that which is only a }, u know what i mean?

    so the compiler doesnt always detect the error where the error occurs? why does this happen?
    Most parsers can only detect the missing semi colon when it can tell that a right-sided production cannot be reduced. By this I mean replace something like int f(); with a higher level meaning to it such as function_declaration. When parsing code such as

    Code:
    void f() 
    
    
    int g();
    the compiler reads in the line with read f() and then the blank line searching for semicolon to reduce "void f();" into a function declaration. Only when the parser sees the int token is it able to tell that it cannot reduce. But by then the line number is two lines down from where you think the error occurred. Of course, like most things with computers, where you think the error occurred is not always so obvious. This code is just as valid as putting the semicolen on the same line.

    Code:
    void f()
    
    
    ;
    void g();

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    This is valid too:
    Code:
    void
    f
    (
    
    ); void
    
    g( );
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Depends, I think, what valid means. Only by the GNU coding conventions would that code have a prayer, though the code must still be flushed left http://www.gnu.org/prep/standards_23.html#SEC23

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Detecting compiler
    By Scarvenger in forum C++ Programming
    Replies: 7
    Last Post: 12-20-2007, 02:12 PM
  3. Compiler Errors with Getline()
    By dac in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2006, 11:58 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 03:57 PM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 04:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21