delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/28/11:55:56

Message-Id: <3.0.6.32.19990228114416.0097d4c0@pop.globalserve.net>
X-Sender: derbyshire AT pop DOT globalserve DOT net
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Sun, 28 Feb 1999 11:44:16 -0500
To: djgpp AT delorie DOT com
From: Paul Derbyshire <pderbysh AT usa DOT net>
Subject: Re: sin, cos ??
In-Reply-To: <Pine.SUN.3.91.990228152640.5950u-100000@is>
References: <3 DOT 0 DOT 6 DOT 32 DOT 19990228075415 DOT 008acda0 AT pop DOT globalserve DOT net>
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

At 03:34 PM 2/28/99 +0200, you wrote:
>
>On Sun, 28 Feb 1999, Paul Derbyshire wrote:
>
>> 1. M_PI is a macro.
>
>So are stdin and stdout.  If you want to avoid macros, you won't get
>very far.

cin and cout aren't macros. Macros have their place in C++; and that is in
configuration for conditional compilation.

>At the moment it was written, maybe, and for the machine it was written 
>on.  But code tends to live longer than its writers ever imagine.  What's 
>good today, might be bad tomorrow (e.g., if double becomes 80 bits).

const long double pi = 4*atan(1);

will work forever, as long as the libm you use stays current. (Of course,
it won't work in plain C...)

I think the final version of the C++ standard expects a "const long double
pi" or something very similar in the standard C++ library, anyways.

>No, they don't have any side-effects, period.  Nate took all the 
>precautions that are needed to that the macros will work with any 
>pathological arguments.

Can Nate make this work without side effect problems?

#define MAX(a,b) (((a) > (b)) ? (a) : (b))

(Hint: think MAX(i++, j++). <evil grin>)

>You sound like the "goto considered harmful" argument of yore.

Goto has its place. Which is usually out of sight of users and well-commented.

>Nothing should be brought ad absurdum.  Macros should be avoided
>*when* they are dangerous, and if there's a better tool to achieve the 
>same goal.

In C++, the latter holds true for all uses except conditional compilation
related stuff. In either C or C++, the former holds under complex (although
well defined) conditions none of which include conditional compilation.

>I have yet to see a non-trivial program which doesn't use macros (and 
>goto's).

I've seen plenty of nontrivial programs that use macros only to control
compilation on different platforms, with nary a goto in sight.
-- 
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://surf.to/pgd.net
_____________________ ____|________     Paul Derbyshire     pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019