TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAN MCGREGOR
from: DARIN MCBRIDE
date: 1997-07-21 22:00:00
subject: Sunir ventures into C++

 -=> Quoting Dan McGregor to Sunir Shah
 SS> /* 1. Passing by reference */
 SS> void foo( int& HeyIMagicallyAlterYourVariableWithoutTellingYou )
 DM> It can be avoided.
OTOH, it shouldn't be.  Passing by reference is a very strong aspect of the
language, one that C can only simulate.  The idea, to me, anyway, is that
code becomes a lot cleaner when you can pass by reference.  You do it all the
time in C, but C++ allows it not to be so ugly.
scanf( "%f", &float_var);
(Ignore, for the moment, that scanf is one of the hardest functions to
understand... )
cin >> float_var;
The latter is by _far_ more elegant.  (And, often, faster, although only
marginally so in this case due to the use of floats...)
 SS>     /* 2. Declaring data in random places */
 SS>     int HiIAmRandomlyDeclaredHere;
 DM> Well C++ allowes it.  Its up to the programmer to do it :)
For good reasons!  One is const-correctness.  Sometimes you can't create a
variable that would otherwise be const until after executing a number of
other functions.
void foo(int a)
{
  int b = get_some_other_var();
  set_up_environment(b);
  const int c = b + a * get_some_environment_int();
  // use c, which now won't change again.
}
Another is keeping a variable close to its use.  If you only use a variable
for a few lines of code near the end of a function, there's no point in
defining it at the top of the function.  The scope of a variable can be
vastly reduced in this manner.  Reduced scope is a Good Thing.
 SS>     HiIAmRandomlyDeclaredHere = ButICannotFindWhereHereIs; // a=b
 SS>                                        /* 3. Assembly comments */
 DM> I like them actually...
To a point, they're useful.
 SS>     /* 4. C-style casts are outlawed as of the latest draft proposal */
 SS>     long bar;
 SS>      int baz = (long)bar;
 DM> Strange.  I use type casts all the time.  IE:
 DM> char *i;
 DM> i = (char *) malloc (30 * sizeof (char));
1. It's no longer permitted.  Use the *_cast() functions instead.
2. malloc is a C-ism.  Use new/delete instead.
 SS>     /* 5. Weird new commands and stuff because I hadn't bothered to
 SS>     ** call ANSI to see what they threw in this morning.
 SS>     */
 SS>     CATCH TRY IAMAFISH THESE_ARE_ALL_VALID BECAUSEC++CHANGES EVERYWEEK;
 DM> Try and Catch are quite usefule exception handling things...
Sunir has to relax - if his compiler isn't up to date with "this morning's"
advancements, he can't use 'em anyway.  Besides, if he doesn't want to use
'em, don't.  I still don't bother with exceptions.
 SS> No surprise. Borland is evil.
 DM> Not as evil as Micro-Soft.
No comment.
[Team OS/2]
[IBMer]     (*)
[wise-arse]
Hey, who threw that last one in there?  Sunir, you been hackin' my machine
again?  :-)
(*) Standard employment disclaimer applies
... I am Ohm of Borg.  Resistance is voltage divided by current.
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.