Using (abusing) cpp..

diamond@tkovoa diamond at tkou02.enet.dec.com
Thu Apr 12 17:06:38 AEST 1990


In article <3358 at jato.Jpl.Nasa.Gov> hashem at mars.jpl.nasa.gov (Basil Hashem) writes:

>I am not sure this is the most appropriate group, but let me try.

It is.

>#if (LANGUAGE == French)
>#define GREETING       Bonjour
>#else
>#define GREETING       Good Morning
>#endif

>What I really need is a [preprocessing-time] strcmp(LANGUAGE, "French")
>but I can't really do that considering this is not C.

In fact, some programs (including a certain famous C-compiler itself, pcc)
need a similar feature.  "If you want PL/I, you know where to find it."

The way pcc solves it is by #include of a header file with such things as:
  #define English 1
  #define French 2
  #define German 3

Since un"define"d preprocessor identifiers turn into zeroes in #if expressions,
there is an advantage to not using 0 for a valid option.  You can check:
  #if (LANGUAGE == 0)
  #error You set LANGUAGE to an unknown language (or you forgot to set it).
  #else
  ...

-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This_blank_intentionally_left_underlined________________________________________



More information about the Comp.lang.c mailing list