Re: Why C/C++ errors are SO obscure/devious??
- From: "Ed Vogel" <edward.vogel_stop_the_spam@xxxxxx>
- Date: Wed, 31 Aug 2005 13:55:40 GMT
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.
.
- References:
- Why C/C++ errors are SO obscure/devious??
- From: Massimo Soricetti
- Why C/C++ errors are SO obscure/devious??
- Prev by Date: Re: MACRO exclusion
- Next by Date: Re: two's complement done before storage or on the fly while computing
- Previous by thread: Re: Why C/C++ errors are SO obscure/devious??
- Next by thread: confused abt file operations
- Index(es):
Relevant Pages
|