From owner-freebsd-chat Wed Mar 6 11:50:38 2002 Delivered-To: freebsd-chat@freebsd.org Received: from tepid.osl.fast.no (tepid.osl.fast.no [213.188.9.130]) by hub.freebsd.org (Postfix) with ESMTP id 6D95337B400 for ; Wed, 6 Mar 2002 11:50:30 -0800 (PST) Received: from raw.grenland.fast.no.fast.no (raw.grenland.fast.no [192.168.48.104]) by tepid.osl.fast.no (8.9.3/8.9.1) with ESMTP id UAA18051; Wed, 6 Mar 2002 20:50:18 +0100 (CET) (envelope-from Raymond.Wiker@fast.no) From: Raymond Wiker MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15494.29430.907768.151847@raw.grenland.fast.no> Date: Wed, 6 Mar 2002 20:50:14 +0100 To: nate@yogotech.com (Nate Williams) Cc: Raymond Wiker , Giorgos Keramidas , Terry Lambert , "Steve B." , freebsd-chat@FreeBSD.ORG Subject: Re: C vs C++ 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> X-Mailer: VM 7.00 under 21.1 (patch 12) "Channel Islands" XEmacs Lucid Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 #include 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