Re: Why C/C++ errors are SO obscure/devious??



As other replies have pointed out, many development environments
provide the functionality you request.

I think another reason is that producing error messages is not considered
a "sexy" part of a compiler. Most compiler writers worry about things
such as code optimization. If you look at most books on writing compilers,
and especially if you look at technical papers, generation of efficient
code is the main topic. I bet you'll find very few PhD theses written
on compiler diagnostic, but many many writen on optimizations.

With that said, to address some of your specific issues:

> It's not uncommon to forget a } writing code, and at compiling time get an
> error 18956778 lines after the mistake, in an otherwise absolutely correct
> piece of code.

The compiler I work on will attempt to detect the { that was missing a
close brace.

> And in general, I noted that many, if not all, error messages from the
> compiler are VERY short and cryptic, while a couple of words more could
> sometimes help a lot in understanding what's wrong and where, for newbies.

Our compiler's message tend to be rather long. In fact we sometimes get
feedback saying they are too long. For example, here's something that
gets posted to this newsgroup all the time. Consider the program:

void bar(int a, int b);
int x;
void f(void) {
bar(x++,x++);
}

lint will emit:
"t.c", line 4: warning: x evaluation order undefined

Our compiler's message is:

bar(x++,x++);
....1
(1) Warning: In this statement, the expression "bar(...)" modifies the
variable
"x" more than once without an intervening sequence point.
This behavior is undefined. (undefvarmod)

> Well, not only for them... maybe a compiler switch --NOOB_ERR_MSGS could
> be very handy for some people :o)

We can do this too...if you add the -verbose switch you'll see:


bar(x++,x++);
....1
(1) Warning: In this statement, the expression "bar(...)" modifies the
variable
"x" more than once without an intervening sequence point.
This behavior is undefined. (undefvarmod)

Description: The compiler has detected a case where the same variable
has been modified more than once in an expression without a sequence
point between the modifications. Because what modification will occur
last is not defined, this expression might produce different results on
different platforms.
User Action: Rewrite the expression so that each variable is modified
only once.

Is this enough??

> Why can't a compiler give more accurate informations about errors?

Because most compiler writers are paid to have their compilers generate
better code.

> Shouldn't this save time, stress and money?

Yes...I think it would. Have you written to your compiler supplier and
requested better messages?

Ed Vogel
HP C for OpenVMS and Tru64 UNIX Engineering.



.



Relevant Pages

  • Re: Capturing error line on exception (SWI)
    ... > print_message/2 to catch and print error messages. ... > prevent the compiler from stopping after the first error. ... > an explicitely passed input stream to avoid trouble with directives that ... > may modify the current input stream and do really weird things. ...
    (comp.lang.prolog)
  • C Compiler Errors (For Real).
    ... These are some of the error messages produced by Apple's MPW C ... afternoon and decompiled the String resources for the compiler.) ... "Can't cast a void type to type void (because the ANSI spec. ... "This label is the target of a goto from outside of the block containing this ...
    (rec.humor.funny.reruns)
  • Re: The Decline of C/C++, the rise of X
    ... >> Jim points out later, and poorer error messages on a syntax error, as ... > clearly identify the position of an error is a feature of a compiler ...
    (comp.programming)
  • Re: The Decline of C/C++, the rise of X
    ... >> Jim points out later, and poorer error messages on a syntax error, as ... > clearly identify the position of an error is a feature of a compiler ...
    (comp.programming)
  • Re: The Decline of C/C++, the rise of X
    ... >> Jim points out later, and poorer error messages on a syntax error, as ... > clearly identify the position of an error is a feature of a compiler ...
    (comp.programming)