4

I'm trying to obtain something like:

#if (!defined(SVN_REV) || (SVN_REV==""))
   char svnrev[10]="not found";
#else
   char svnrev[16]=SVN_REV;
#endif

to handle the case that the compiler, not finding a particular environment variable, sets:

define SVN_REV ""

which for me should be treated same as the define is missing.

But it seems that this is not possible, did anybody found a way to achieve the result?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
giuspen
  • 1,365
  • 3
  • 20
  • 33

1 Answers1

0

No, the C preprocessor doesn't compare strings.

You can do:

#if !defined SVN_REV
#define SVN_REV "not found"
#endif
const char *svnrev = SVN_REV;

To achieve the same effect.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • 5
    But this does not cover the case that Visual C++ (which in the case does not find a particular environment variable) defines SVN_REV as an empty string - so it is defined but as empty which for me is like not defined. Probably it is not possible to obtain the result only with preprocessor code. – giuspen Jan 23 '15 at 15:34
  • 2
    This is not an answer to the question... :( – Zordid Mar 13 '19 at 15:37