Compiler Specific Operators

levy at ttrdc.UUCP levy at ttrdc.UUCP
Sun Jul 13 10:32:25 AEST 1986


In article <2364 at umcp-cs.UUCP>, chris at umcp-cs.UUCP (Chris Torek) writes:
>	/* math.h */
>	double	_builtin_sin(double x);	/* and the compiler version */
>	#define	sin(x)	_builtin_sin(x)	/* default to the compiler version */
>...
>Note that this has some, er, `interesting' implications:
>	#include <math.h>
>	double
>	subr(double (*fp)(double arg)) {
>
>		return ((fp)(3.1415926535897932384626433832795));/* approx */
>	}
>	strange() {
>
>		... subr(sin) ...	/* NOW what? */
>	}
>This seems to call subr(_builtin_sin).  The draft standard says that
>because `sin' appears here without a following `(', it is not macro-
>expanded; thus this in fact passes the address of the library function.

If so, this is a "new" feature at least compared with AT&T SysV (could
someone check out BSD and others?) C compilers, which give an error message
about "argument mismatch" if something like this is tried.

Given that this is supposed to be a "standard," I wonder what C compilers
support this now?  I thought standards were supposed to, er, be codifications
of a combination of the best features in existing compilers, not invent
things out of the blue sky...
(isn't this the way the Fortran 66 and 77 standardizations worked, for
example?).  Not that treating macros this way is a bad idea, I just would
like to know who does it now.

>In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
						vax135}!ttrdc!ttrda!levy



More information about the Comp.lang.c mailing list