Passing types to a subroutine

Dave Jones djones at megatest.UUCP
Thu Nov 10 15:25:00 AEST 1988


>From article <14457 at mimsy.UUCP>, by sjr at mimsy.UUCP (Stephen J. Roznowski):
> I'm in the process of developing a piece of code that needs
> to be portable across several different machines.  ...

[ How to switch between using floats and doubles? ]

If I understand the question, you can do it as follows.  Declare
a typedef for the type "real".  Use "real" everywhere instead of
"float" or "double".

#ifdef FLOATS
typedef float real;
#else 
typedef double real;
#endif

You should be sure you are familiar with the way floats are
cast to doubles on procedure calls, etc..  (See K&R)  If your machine
uses IEEE floating point format, the cast operation takes a nontrivial
amount of time.



More information about the Comp.lang.c mailing list