How to force cpp to abort?
Nathan Sidwell
nathan at elberton.inmos.co.uk
Fri Aug 17 19:12:17 AEST 1990
In article <MIKEG.90Aug11180036 at c3.c3.lanl.gov> mikeg at c3.c3.lanl.gov (Michael P. Gerlek) writes:
>
>I'm writing some machine dependent code...
>
>#if defined(__convex__)
> (do Convex stuff)
>#else
>#if defined(cray)
> (do Cray stuff)
>#else
>#if defined(sun)
> (do Sun stuff)
>#else
> (oops) /* force abort */
>#endif
>#endif
>#endif
>
>[how to tidily abort compile at oops]
You can use the #error preprocessor directive, viz
#error Machine type not supported
I would have emailed this, but it struck me that it also helps in another
thread about array initializing. When I define an initialized array in a
header file, and initialize it in the code file, the two must be kept in step.
Ie
"module.h"
#define DETECTORS 7
extern char *detectors[DETECTORS] ;
"module.c"
#if DETECTORS != 7
#error Module assumes DETECTORS == 7
#endif
extern char *detectors[DETECTORS] =
{
"Photomultiplier",
"Silicon",
"Raman",
"Detector 3",
"Detector 4",
"Detector 5",
"Detector 6",
};
Much better than a comment telling me to keep them in step!
Nathan Sidwell, INMOS Ltd, UK JANET: nathan at uk.co.inmos
Generic disclaimer applies UUCP: ukc!inmos!nathan
My indicision is final (I think) INTERNET: nathan at inmos.com
More information about the Comp.lang.c
mailing list