Understanding Error Messages

Usually when I've made a mistake in the source code, I generally just go off the line number and find that it's generally a typo. But a lot of it doesn't make sense to me completely just yet. I was wondering if anybody has suggestions on learning to read those errors, such as uploaded code that purposefully contains errors, a website, or possibly even a book. Fortunately I don't mistype that often, but at the same time it limits my exposure to the error messages.

Thanks in advance!

I just now thought that the error messages are probably IDE specific though aren't they?
Last edited on
closed account (zb0S216C)
Reading errors can be simple, but some errors can be damn right cryptic. When reading an error, highlight the important parts of the message and go from there. For example:

d:\repository\c++\test projects\console\console\console.cpp(20): error C2143: syntax error : missing ')' before '{'

This can be a bit of an eye-strainer for a beginner, but if your strip away the unnecessary information, you're left with this:

console\console.cpp(20): missing ')' before '{'

This is far more simpler to parse. From this information alone, I know the folder, file, line, and the error itself. Lets do the latter again, this time, with a more complex error. To start, I'll post this little code snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template< typename T >
void Function( T &X )
{
    std::cout << X << std::endl;
}

// Create a simple structure.
struct Simple
{
    int A;
    char B;
} SSimple;

// Call the function.
Function< Simple >( SSimple );

Clearly, this code has many issues with it. However, this was made to generate a complex template error.

When I called this function, I received this error:

d:\repository\c++\test projects\console\console\console.cpp(19): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'SSimple' (or there is no acceptable conversion)

At first, a beginner would be like: WTF is this cryptic nonsense? As I said before, breaking the error down is the best thing to do. So, if I strip this error message down, I get:

console\console.cpp(19): binary '<<' : no operator found which takes a right-hand operand of type 'SSimple'

This message is telling me that the operator << has no overloaded version that takes an instantiation of Simple as an operand. Since I stripped away the directory, the message instantly became more clear. Now, to do the actual parsing of this error message. This message can be divided into 2 parts, which are:

Section A) binary '<<'
Section B) no operator found which takes a right-hand operand of type 'SSimple'

Section A indicates the operator that is causing the problem. This narrows the scope to that operator on the stated line.

Section B is the actual error. Reading this section reveals the word operand. An operand, in a nutshell, is an argument that is used either on the left or right-hand side of an operator. An operand can be anything, as long as it's supported by that operator. The "right-hand operand" part indicates that the operand I passed to the right-hand side of the operator << is not supported. So, there's my error.

Need a more complex example?

Wazzak
Last edited on
I pretty much get the concept of breaking it down, especially with the way you explained it. But a more complex example would be greatly appreciated. Like I said, I haven't seen them too often yet, I guess with more experience I'll run into them more and more. But getting a handle on before I start getting into the later chapters in the book I'm going through (particularly those exercises) would be very helpful.
closed account (zb0S216C)
AKat wrote:
But a more complex example would be greatly appreciated. (sic)

Sure. I'll use the URES (Unresolved external symbol) error.

The Unresolved External Symbol Error

This is one of the most confusing, especially with large function interfaces. The complexity of the error may depend on the compiler, but Microsoft's Visual C++ compiler is quite complex. So, without further ado, here's the error:

unresolved external symbol "int __cdecl Function(int)" (?Function@@YAHH@Z)

In a short summary, the linker cannot find the definition of Function( ). But how exactly did I arrive at that conclusion? Well, as I said in my previous post, you've got to break the message down and remove unnecessary information. After removing the linker information, I was left with this:

unresolved external symbol "int __cdecl Function(int)"

To read this, I need to know what an unresolved external symbol is. An unresolved external symbol is a symbol (also known called an identifier, or name) that the linker could not find during the linking process. The __cdecl is the calling convention for that function. This message has provided me with the return type-specifier, symbol and parameters of the function that the linker can't find. Now I know which function I'm targeting, and it's up to me to provide the linker with a definition of this function.

An URES error can be thought of as a new word within the dictionary. For example, say I created a new word called susire and I didn't provide a definition (or true meaning) for the word. When people (the linker) use that word, they don't know what it means, so they get confused.

Wazzak
Holy source code Framework! :)

But yeah, I see how breaking it down helps quite a bit. If I as to have received an error like that the first thing I would of done was scratched head... crossed eyes... sighed... pulled up google and start thinking maybe it has to do with debugging symbols for the MS debugger.

Thanks Framework for the info.
Topic archived. No new replies allowed.