views:

77

answers:

2

I'm using Visual Studio C++ 2008 Express Edition.

Is it possible to modify the text in the Output pane for compilation (or other) errors?

For example, I might receive an error that reads: error C2556: int Class::getResult(void) + a lot more relative garbage.

I can parse the output text and find and fix my mistakes easily. It would still be nice/useful if I could modify the errors to make them cleaner, shorter, and more friendly. An example would be receiving an error that read: "Source.cc (Line 10): Missing a closing;"

+3  A: 

There are a few things you have to understand. The compiler is really doing the best it can; it tells you exactly where it failed, and the entire compilation up until that point. It doesn't know what you intended to write, it knows what you wrote, so how can it possibly assume an error was caused by something else more remote? I think if you were writing it and got to the point of making errors "cleaner, shorter, and more friendly", you'd realize this is much more difficult that it might seem.

There are situations when it can do that, and compilers are getting better at suggesting them it seems. For example this:

if (x);
{
    x = 5;
}

Produces a warning:

warning C4390: ';' : empty controlled statement found; is this the intent?

But they can't always do that.

That all said, the error messages are really all you need to solve the problem, once you learn the language a bit and understand what it all means. I think it's an enormous myth and exaggeration that template errors are "evil and cryptic". While they can be verbose, they're really not that hard to understand at all. I don't think it's template errors being cryptic, I think it's the reader not knowing how to read it well, which makes it seem cryptic. But if you take your time, you see exactly what it was trying to do and where it failed.

There were a thing called "concepts" that would appear in the next standard, C++0x, that would fix this up immensely. They were sort of like tags that classes could fit into if they supported everything that tag said they had to. So in std::copy, instead of errors about being unable to call operator= on something, along with the errors that propagates, you would simply get something like "Error: Type is not CopyAssignable" and that would be it. Same error, different presentation. And that's also the reason they got cut out, for now. they were proving to be trouble, and since it was syntactic sugar anyway, it's more important to work on other things. Hopefully we'll see them someday.

Now, there is a tool called STLFilt, which will filter template errors concerning things in the STL. I have never used it, but I've heard it recommended more than once. Here's one of their sample filters. You might give it a try.


Since you seem to think this is something possible to do in the language itself: nope. The language has no concepts of what errors messages should look like or what should warn or what shouldn't.

You'll find what I mean in the standard in section 1.4/2. Summarized, it basically says "If there's an error, output something about it". That's it.

GMan
Gman, as said in the original post, I can already parse the output easily enough, and fix my errors easily enough.What I want to know is whether or not *it is possible to change the output text to something more friendly*.Somewhere in C++ - and perhaps this is defined in the compiler itself, when ERROR X is generated, it's accompanied by text "ERROR X: You made such and such a mistake".I want to know if I can change the text to say "ERROR X: This error code = this problem, go fix this at line y".
Matt
@Matt: No, you need to be the compiler writer, and a damn good one at that. Your oversimplifying your task; it's easy for you to think "obviously, I should go to this line to fix it", but you're a human. *Computers don't have that luxury* in terms of identifying things, and your task would likely be very difficult.
GMan
@Gman - So the error messages are determined by whatever entity wrote the compiler? I.E., they can't be changed?Great, answers my question, although I wish it were otherwise.
Matt
@Matt: Indeed. Compilers provide ways to interject, as STLFilt takes advantage of it, but in general they are pretty hard coded I think.
GMan
A: 

It's pretty easy to take your best shot at this problem. The compiler itself is a command-line program named cl.exe. If you want to filter its output, what you need to do is create a program that's also named cl.exe. It will need to pass all the command line arguments through to the original cl.exe. Then it'll take whatever the original one produces as messages on its standard output, parse them, replace them with the messages you prefer, and print those to its own standard output.

When you do that, you'll probably want to at least retain the information about the file and line where the problem occurred in the original format. The IDE parses and uses that to support navigating among errors (e.g., with F4 or double-clicking).

Jerry Coffin
Well that gives me something to think about it. It's just a little bit out of my reach right now; at the very least my idea is no longer, to quote the Simpsons, "umpossible". Thanks Jerry.
Matt