Re: A C++ Whishlist

From: Ram Firestone (bichir_at_covad.net)
Date: 03/19/04


Date: 18 Mar 2004 20:38:29 -0800

oldwolf@inspire.net.nz (Old Wolf) wrote in message news:<843a4f78.0403181343.6d3c6267@posting.google.com>...
> > > > > #include <iostream>
> > > > > class foo
> > > > > {
> > > > > int a;
> > > > > public:
> > > > > void dump() { std::cout << a << std::endl; }
> > > > > };
> > > > >
> > > > > because someone might write:
> > > > >
> > > > > int main()
> > > > > {
> > > > > foo *f = NULL;
> > > > > f->dump();
> > > > > }
>
> [snip: a screenful of argument about whether or not to throw exceptions]
>
> My class foo cannot throw an exception, if UB has not been introduced
> by someone else already. So the current Standard is better in this
> respect too.
>

Except your class can and will throw an exception on almost every
computer. That's what I meant by a fantasy world. On your fantasy
computer your member function can't throw an exception.

> > > My function "foo::dump()" can never introduce undefined behaviour,
> > > according to the current Standard.
> > >
> > > Encapsulation is one of the cornerstones of C++ : I can take
> > > this class foo and use it anywhere, anyhow I like, in any project
> > > at any time in the future, and be 100% certain that it will never
> > > introduce undefined behaviour, regardless of how it is called.
> > > The same cannot be said of your func.
> >
> > In a fantasy world this is true
>
> In the real world this is true. There are millions of C++ components,
> classes, etc. which have been debugged and tested and then re-used
> in a variety of applications. If we give my class foo a suitable
> constructor, then it can join that list.
>

And they will all crash in the exact same place if you call their
members with a NULL pointer on almost all computers out there. On the
any others they will crash before the member call. So what's your
point? The result is the same.

> , in reality almost all compilers will
> > pass your NULL though to the this pointer so you are in the exacty
> > same boat I am.
>
> Not at all. I couldn't care less if someone introduces UB and then
> attempts to use my class. The bottom line is that my class cannot
> introduce UB and yours can. Both of our examples are equally as
> efficient. Mine is already robust; if you want to make yours robust
> then you have to add in an extra check against NULL.

You know I can't argue with you because I don't think have an
understanding of what happens in a member function call. Again your
class is robust on very few computers if any. In addition the outcome
is the same if you call a member with NULL on all computers, the
program crashes. Bottom line, if you want the program to be robust you
have to put in a check and handle it somewhere. You never get it for
free. Doesn't matter if the standard is changed or not. It still
crashes. If want it to crash outside of you class you have to put in a
check because the calling through NULL is undefined which means that
if you do it you can't guarantee that the this pointer will not be
NULL and in almost all cases it will actually be NULL. You can whine
to the gods about standards and well-formed programs forever and in
the end the this pointer will still be NULL and your program will
still crash. Your robustness advantage is strictly in your head.

Ram



Relevant Pages

  • Re: Apple issues warning on Vista
    ... McDaniel wrote: ... Which is why you keep calling normal computers "Windows Vista". ... And when you use the word 'standard' instead, ... Operating System of the great majority of Intel-based computers. ...
    (comp.sys.mac.advocacy)
  • Re: BS7799 and ISO17799
    ... as a Cerified Auditor to audit against the BS7799 Standard. ... > I think a guy called William 'T' Morris may have had this idea first. ... In 1988, the ARPANET had its first automated network security incident, ... explosion of copies to be started at computers all around the ARPANET. ...
    (Security-Basics)
  • Re: Apple issues warning on Vista
    ... Which is why you keep calling normal computers "Windows Vista". ... The word 'standard' means a LOT more than you are trying to use it for. ... Operating System of the great majority of Intel-based computers. ...
    (comp.sys.mac.advocacy)
  • Re: Is there another way ??
    ... > I find it humorous that people blindly follow Microsoft's advice to ... You find it humorous that people who know nothing about computers and feel ... these users have to do in most cases in learn a minimum of standard ... practices and their systems will work find. ...
    (microsoft.public.windowsupdate)
  • Re: Youre appointed as Portability Advisor
    ... None of its behaviour is undefined by the Standard. ... to write to member A of a union and then read from member B, ... character type that treats the thing as an array of bytes. ... dereferencing a pointer to one ...
    (comp.lang.c)