Article View: comp.os.os2.programmer
Article #3567Re: emx/gcc very forgiving!!
From: Colin Jensen
Date: Sat, 23 Jan 1993 19:20
Date: Sat, 23 Jan 1993 19:20
57 lines
2935 bytes
2935 bytes
In article <1jkjleINNfn9@gap.caltech.edu> brooke@cco.caltech.edu (Brooke Paul Anderson) writes:
>byu@sys.toronto.edu (Benjamin Yu) writes:
>
>>In article <1993Jan20.045839.25052@netcom.com> ljensen@netcom.com (Colin Jensen) writes:
>>>I use a hybrid gcc/2 gcc-2.3.3 compiler, and it says:
>>>forgive.cc:6: warning: assignment of non-`const *' pointer from `const *'
>>>
>
>>emx/gcc does indeed give a warning, but I was hoping it wouldn't even allow it ..
>>hence I call it "forgiving"!
Benjamin is right. The C++ Annotated Reference Manual (ARM) indicates that
this must be considered an error. Gcc issues a warning - but the ARM says
that this is not good enough. Personally, I think the ARM is being overly
pedantic.
>>>>It allows me to have amibiguous overloaded functions.
>>>Not sure what you mean. How about a sample?
>>>
>> elevator() { floor_selected = 0; floor_number = 0;} ;
>> elevator(int x = 10, int y = 10) { floor_selected = x; floor_number = y; };
>
>If it gives you a warning, I'd say that's good enough. Also, your
>overloaded function doesn't look ambiguous at all to me. One takes two
>ints as arguments; the other takes no arguments.
The code
elevator(int x=10, int y=10)
indicates that it is legal to call the second elevator function with
zero arguments (and that x will be 10, and y will be 10 in the called
elevator() function).
Clearly, the first elevator function is also intended to be called with no
arguments.
Therefore, is you write some code like
if (foo) elevator();
either version of the overloaded function elevator "matches" this
call pattern - in other words elevator() is ambiguous.
The ARM states that the declaration of the two ambiguous elevator
functions should generate an error. Gcc does not. In this case gcc
fails to even warn about the problem - even if you *use* the elevator()
function.
The real problem is that the C++ language is so @#$%^& complex that
it is a very difficult language to parse correctly for legal programs.
Parsing the wrong programs and noticing what is wrong is even harder.
For example, the excellent Borland C++ 3.0 compiler sometimes fails to catch
errors until several lines after the mistake - and it issues an unrelated
error message to boot. And the behavior of the Cfront compiler is
sometimes just bizarre. So it goes.
--
Colin Jensen
ljensen@netcom.netcom.com cjensen@ampex.com
Technical Details
Message-ID:
<1993Jan23.192018.21475@netcom.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!decwrl!csus.edu!netcom.com!ljensenReferences:
<1993Jan20.045839.25052@netcom.com> <1993Jan20.102705.23327@jarvis.csri.toronto.edu> <1jkjleINNfn9@gap.caltech.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!decwrl!csus.edu!netcom.com!ljensen From: ljensen@netcom.com (Colin Jensen) Subject: Re: emx/gcc very forgiving!! Message-ID: <1993Jan23.192018.21475@netcom.com> Organization: Netcom - Online Communication Services (408 241-9760 guest) References: <1993Jan20.045839.25052@netcom.com> <1993Jan20.102705.23327@jarvis.csri.toronto.edu> <1jkjleINNfn9@gap.caltech.edu> Date: Sat, 23 Jan 1993 19:20:18 GMT Lines: 57