Thread: This is the stupiest compiler error I've ever seen

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    23

    This is the stupiest compiler error I've ever seen

    Code:
    list.c:35: error: void value not ignored as it ought to be
    This is the code:
    Code:
    Table *create(void)
    {
    	return NULL;
    }
    
    void init(Table **table)
    {
    	clear(table)
    	*table = create(); // line 35
    }
    As you can see I'm not passing anything into create(). Tried changing it to create(void)...no luck.

    I tried googling it, but most of the results don't pertain to what I'm attempting to do.

    I'm using gcc compiler (there is a bug report on it @ http://gcc.gnu.org/ml/gcc-bugs/2003-08/msg01200.html... but the workaround doesn't do any good).

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    What is your function prototype for create()? Does it have void listed as the parameter?

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Well what if you just change your function to:
    Code:
    Table* create()
    {
        return NULL;
    }

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I would keep the void in there if you can because there is a different between the two in C. I can't remember the particular difference between C89 and C99, if there is one. I need to look that up, but I think C99 is a little more strict on void vs empty parameters.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Yeah, blame the "stupid" compiler.

    Code:
    void init(Table **table)
    {
    	clear(table) <-- missing semicolon.
    	*table = create(); // line 35
    }
    That parses as clear(table) * table = create(). clear() probably returns void. You can't multiply a void by a "table." The compiler spits this error.

    Blaming the compiler just blinds you to reality...

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Bah, I can't believe I missed that. LOL. Nice spot, brewbuck.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    23
    Quote Originally Posted by brewbuck View Post
    Yeah, blame the "stupid" compiler.

    Code:
    void init(Table **table)
    {
    	clear(table) <-- missing semicolon.
    	*table = create(); // line 35
    }
    That parses as clear(table) * table = create(). clear() probably returns void. You can't multiply a void by a "table." The compiler spits this error.

    Blaming the compiler just blinds you to reality...
    LOL. I blame the compiler anyway for giving me the wrong error message

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by TalonStriker View Post
    LOL. I blame the compiler anyway for giving me the wrong error message
    If I make a compiler, I think I need to invent really interesting error and warnings messages.

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by TalonStriker View Post
    LOL. I blame the compiler anyway for giving me the wrong error message
    It gave precisely the right error message. Your code was trying to multiply something by a void value. Just because you didn't THINK that was what your code was doing doesn't change that fact. The compiler is not going to start guessing, "Hey, maybe there should have been a semicolon here... or here... or maybe here?"

    Sometimes a parse error is unambiguous and leads to a very clear error message. But in this case, it wasn't even a parse error, but a semantic error. How on earth would you expect the compiler to know that you "meant" to put a semicolon there?

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Maybe the compiler could check to see if the line causing the error spans 2 or more lines and then dynamically add semicolons to the end of the lines to see if that fixes it. If it does, print an error telling the user to add semicolons, otherwise print the original error.

  11. #11
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by cpjust View Post
    Maybe the compiler could check to see if the line causing the error spans 2 or more lines and then dynamically add semicolons to the end of the lines to see if that fixes it. If it does, print an error telling the user to add semicolons, otherwise print the original error.
    How can the compiler know that the original error wasn't that clear() should have been defined to return something other than "void?"

    As I said, the compiler interpreted this as a semantic error, not a syntactic one. How far must the compiler go? How many billion ways can the compiler inject small syntactic changes to correct a semantic error? This is not the compiler's job.

    Also, adding a comma would work just as well as a semicolon. Again, how does the compiler know what you want?
    Last edited by brewbuck; 12-02-2007 at 03:25 PM.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I would think that putting "lines 34--35" in the error message would be enough of a hint without the compiler having to try a bunch of things. I don't know of any compiler that does that, though (admittedly I don't have a very complete collection).

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by tabstop View Post
    I would think that putting "lines 34--35" in the error message would be enough of a hint without the compiler having to try a bunch of things. I don't know of any compiler that does that, though (admittedly I don't have a very complete collection).
    Or the programmer could just learn the basic rule that, if an error message doesn't make sense on the line it was reported on, look at previous lines until you find it.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sometimes it isn't always easy to see why the compiler is complaining.
    The more information the compiler can give, the better.

  15. #15
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by tabstop View Post
    I would think that putting "lines 34--35" in the error message would be enough of a hint without the compiler having to try a bunch of things. I don't know of any compiler that does that, though (admittedly I don't have a very complete collection).
    That's a good idea actually.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM