1

Given the following C source code

#ifdef FOO
int bar = 1;
#endif
#if FOO == 0
int x = 0;
#elif FOO == 1
int x = 1;
#elif FOO == 2
int x = 2;
#endif

I can preprocess the source code (e.g. with unifdef / coan) as if FOO was either undefined, defined at all or defined as a specific value (coan -DFOO=1 ... would rewrite the code as int bar = 1; int x = 1;).

However, for some variables I want to preprocess on (e.g. _MSC_VER) I don't know the exact value, but I know which values I want to filter out. Ideally, I could run coan -DFOO!=0 or coan -DFOO>0 to drop the parts that don't match but keep the #ifs that can't be evaluated yet.

Is there any preprocessor that can handle more advanced constraints like this?

tstenner
  • 10,080
  • 10
  • 57
  • 92
  • 1
    Your definition of `x` could just be `int x = FOO;`. – Some programmer dude Jun 09 '18 at 18:16
  • Also, you say that you "don't know the exact value [of `_MSC_VER`], but I know which values I want to filter out". That doesn't really make any sense to me. If you don't know the possible values, how can you know what values you want to "filter out"? – Some programmer dude Jun 09 '18 at 18:19
  • There's also `sunifdef` (Son of `unifdef`), but that's intermediate between `unifdef` and `coan` in functionality. I suspect that if `coan` can't do it, there isn't (yet) a tool that does it. I take it that you've decided to stop supporting some antiquated versions of `_MSC_VER` and want to remove the code that depends on versions older than some threshold value. Actually doing that would be hard — and that might be being polite about it if you have code with `#if _MSC_VER >= 3210` or `#if _MSC_VER < 5432` or other more complex constructs. – Jonathan Leffler Jun 09 '18 at 18:34
  • @Someprogrammerdude Let's assume I there are `#ifdef`s for `FOO==0` to `FOO==4` and I want to either remove everything for `FOO=0` _and_ `FOO=1` or keep everything for `FOO=3` and `FOO=4` – tstenner Jun 10 '18 at 16:56
  • @JonathanLeffler coan already has three states - 'matches' (=remove conditional, keep code), 'doesn't match' (=remove everything) and 'unknown' (=keep everything), so the more complex constructs could be left as they are – tstenner Jun 10 '18 at 16:58

0 Answers0