Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Mar 2002 20:50:14 +0100
From:      Raymond Wiker <Raymond.Wiker@fast.no>
To:        nate@yogotech.com (Nate Williams)
Cc:        Raymond Wiker <Raymond.Wiker@fast.no>, Giorgos Keramidas <keramida@ceid.upatras.gr>, Terry Lambert <tlambert2@mindspring.com>, "Steve B." <steveb99@earthlink.net>, freebsd-chat@FreeBSD.ORG
Subject:   Re: C vs C++
Message-ID:  <15494.29430.907768.151847@raw.grenland.fast.no>
In-Reply-To: <15494.23822.972400.759310@caddis.yogotech.com>
References:  <20020305132457.A4700-100000@alpha.yumyumyum.org> <001701c1c481$d0d5eab0$f642d9cf@DROID> <20020305231252.GC5328@hades.hell.gr> <3C8568E0.76415D99@mindspring.com> <20020306032029.GA7926@hades.hell.gr> <15494.13878.219807.949085@raw.grenland.fast.no> <15494.20631.682803.383406@caddis.yogotech.com> <15494.22039.581536.624619@raw.grenland.fast.no> <15494.23822.972400.759310@caddis.yogotech.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Nate Williams writes:
 > >         And exactly *how* is this helped by using printf instead? If
 > > you want to have control of the output using printf, you *still* need
 > > access to class members, including (possibly) protected data.
 > 
 > Easy.
 > 
 > class FP
 > {
 > public:
 >     FP()		{ _value = 0.0; }
 >     FP(double v)	{ _value = v; }
 > 
 >     float getValue() { return _value; }
 > 
 > private:
 >     float _value;
 > }
 > 
 > int
 > main()
 > {
 >     FP f(1.0);
 > 
 >     printf("Value = %3.2f\n", f.getValue());
 > 
 >     return 1;
 > }

       #include <iostream>
       #include <iomanip>

       std::cout << setw(3) << setiosflags(ios::fixed) << setprecision(2) 
                 << f.getValue() << std::endl;

--- this can obviously be simplified (by defining a new iomanipulator).

        How would you go about extending printf et al so that you can
use printf to print a description of an object? With iostreams, this
is trivial.

 > It's not a transient problem when you can't use it *today*.  Try using
 > C++ exceptions on *any* released version of FreeBSD.

        I've been using exceptions in C++ for two or three years
now. Then again, I have _not_ been using them with threads, which
Terry Lambert mentioned somewhere in this thread.

 > Try using it on HP/UX.  Try using it on AIX.  Try using standard
 > containers and see how they behave differently on different releases of
 > Solaris.

        Have you actually _seen_ this sort of behaviour recently?

 > > It's certainly the case that if you don't
 > > require your compiler vendor to comply with the standard, they don't
 > > really have an incentive to provide these features.
 > 
 > Bingo.  If they aren't globally available, then they aren't a standard
 > part of the language.

        Oh, they are. There is a difference between a language
definition and the lowest common denominator between implementations
:-)

 > > Further, if you don't use the advanced features of C++, you may just
 > > as well stick to to C.
 > 
 > Naw, it's still C++.  All versions of C++ support inheritance, scoping
 > protection, object initialization and teardown, as well as
 > function/operator overloading.  Of the above described features, only
 > operator overloading tends to cause strange problems.

        I haven't even seen problems with operator overloading. I
think. It is entirely possible that I may remember something later :-)

 > >  > Safer?  The intracacies of printf/scanf are *well* known, so I wouldn't
 > >  > say that it's any more/less safe.  At least with the above functions,
 > >  > you *know* ahead of time the issues, vs. some random implementation of a
 > >  > class you don't want to look at.
 > > 
 > >         The intricacies of print/scanf may be *well* known, as you
 > > say, but *not* to the average C programmer
 > 
 > This I disagree with.  Back when I learned C in college (late 80s), it
 > wasn't as well known as it is now.  However, even back then we discussed
 > some of the pitfalls of scanf.  With printf/scanf, at least you have
 > only *one* set of routines to deal with.  With streams, you have a bunch
 > of different pitfalls that may vary from class to class.  Simple *is*
 > better.

        Only insofar as it isn't a source of errors. How do you
protect against anyone doing something like

        const char *s = "http://this/is/a/strange/url?%23strange";

        printf(s);

        I've just seen something very similar to this; not involving
printf, but a non-standard string class :-)

        //Raymond.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15494.29430.907768.151847>