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



Massimo Soricetti wrote:
Hello,


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.

This can be efficiently handled in the IDE (Integrated development Environment).

In the IDE of lcc-win32, when you save a file, the IDE will check for
1) mismatched braces, parentheses and brackets
2) Syntax errors
3) Mismtached #if/#ifdef

In the case of mismatched braces it will keep  stack of positions
of opening braces and in most cases it will be able to tell you
where the opening brace is that it is mismatched.

I do not think that this is the job of the compiler itself but it is
the job of the environment where you build your programs.


Or, sometimes in my journeys I got errors reported in a file, checked and found it correct, and discovered it was caused by an error in another file. 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.

This is true, and the lcc-win32 system tries to give as detailed and clear error messages as possible? For instance it avoids: lvalue required

and it says

the left hand side can't be assigned to,
what is (in my opinion) much clearer.

Contrary to many people around, I find that your messages has a very valid reason, and I think it is useful.

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

Why can't a compiler give more accurate informations about errors? Shouldn't this save time, stress and money?


In many cases this is very hard. Error analysis is quite difficult, specially when a missing right brace can completely change the meaning of the program...

Another example: have you ever met the error line "Multiple definitions of..."?

For example, why can't a compiler start a negotiation "on the fly" like this:

ERROR: Multiple definitions of <variable|function|method> X.
X defined:
1) <here1> as variable
<line of code definition...>
2) <here2> as variable
<line of code definition...>
3) <here3> as function
<line of code definition...>
Choose which definition is the right one:

This is "interactive compiling", isn't it? Why not? Why the compiler can't simply ask us, in doubt, and on response modify sources accordingly on its own, in this case and in other similar? This would ease the programming effort a lot.


I think this is out of the question. It is not possible to leave a blatant error in the source code like that, and compiling anyway.

Suppose you said: I want the option 3.

Then you compile, ship the program, and several months later you wonder
My program is crashing but I forgot which option I typed in when the
compiler asked damm. Which one should I debug now?????

jacob

lcc-win32: a compiler system for windows
http://www.cs.virginia.edu/~lcc-win32
.



Relevant Pages

  • alternatives to making blocks like { } or other ??
    ... > But here if there were braces, ... If you were writing in Python the logic would be right also. ... > doesn't meet our coding standards, yet there's no way for the compiler ... > the indentation! ...
    (comp.lang.python)
  • Re: do people really complain about significant whitespace?
    ... there is the potential for them to get out of sync. ... without the programmer adding the surrounding braces. ... The programmer's intent is clear to me as a human, but the C compiler will disagree with me, and in this case, the compiler will be right and I'm wrong. ... Pushing the scutwork down onto tools is not as good a solution as eliminating the scutwork, especially when it shouldn't be necessary at all... ...
    (comp.lang.python)
  • Re: missing out braces
    ... That would be fine if the only thing which read code was the compiler. ... braces add to readability - they mean that things *can't* get ... screwed up just because of indentation, and I can use indentation to ... The braces thing is a personal issue, but I hope you see my point about ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [3/6] kgdb: core
    ... These braces around ... multi-line statements are unneded _for the compiler_, ... me and others reject/fix patches on a ... by the compiler is a style error in only a single, ...
    (Linux-Kernel)
  • 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)