![]() 14. Error Messages Demystified
One of the things you'll be doing the most when programming will invariably be trying to track down coding mistakes the compiler complains about. Here's a list of some common error messages that GCC 4.1 (as included in Mac OS X 10.4.7) will spit out, plus a detailed explanation of the most likely cause of these errors. Conflicting types ... previous implicit declarationmain14.c:46: warning: conflicting types for 'DoNewCommand' What does it mean? GCC reads your source files from top to bottom. When it finds a function it doesn't know about, it usually assumes that it's a function that returns an int and takes ... as its parameters (see man stdarg for details on ... parameters). This assumption is called an implicit declaration, because GCC just assumes that's what you wanted and you were too lazy to write out a declaration. It is also usually a completely wrong guess, though it makes the code compile. When GCC later encounters your actual function definition, it will notice that your parameters don't have the type ... and maybe that it also doesn't return an int and warn you about it in the above fashion. Solution: To avoid this error, either reorder your functions so the called function is above the function calling it and GCC has seen the function before it's first used, or add a forward declaration (see the chapter on headers). operands ... have illegal types ... and 'void'operands of = have illegal types 'int' and 'void' What does it mean? The things to the left and right of an operator (i.e. +, -, *, / etc.) are called operands, meaning "things to be operated on". For most maths statements, the operands would be of type int on both sides, or maybe int on one and float on the other. But in this case, the second operand is of type void, and as we know void essentially means ignore me. You shouldn't be using a value that's to be ignored in an expression. Since you can't really declare a variable of type void (how large would a void be, anyway?), it can't be one of your variables, so what is it? Well, functions that don't have return values are declared as void. So, very likely, you've got a line like the following somewhere in your code: foo = MyFunction( 123 );where MyFunction is declared as: void MyFunction( int n );Or you have some function like in Chapter 5, where we have: void GetArgument( bool isLeft, int* vFirstArg ); which returns its value by reference through the address passed as vFirstArg, and you're calling it like: vFirstArg = GetArgument(true, &vFirstArg ); Solution: Check the types of all variables and the return types of all functions you're using in expressions on the line with the error. Very likely you forgot to specify int or float as the return type from a function, or you wanted a different function. In a case like GetArgument() in Chapter 5, the solution would be to simply get rid of the vFirstArg = part, as the &vFirstArg part combined with the code in the function itself already takes care of assigning the value to vFirstArg.
|
![]() 1. What you need | |||||
| Home | Admin | Edit Last Change: 2008-05-16 @980, © 2003-2008 by M. Uli Kusterer, all rights reserved. |