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?

7
  • Why doesn't it work? how do you know? Commented Jan 23, 2015 at 15:26
  • Visual C++ is complaining that it is "invalid integer constant expression", didn't try on linux gcc/g++ yet Commented Jan 23, 2015 at 15:28
  • No Visual C++ tells that ' define SVN_REV "" ' Commented Jan 23, 2015 at 15:32
  • Why not char svnrev[]="not found"; Let it count the characters for you. Commented Jan 23, 2015 at 16:10
  • 1
    What is "C/C++"? Why is this question tagged C if you are actually writing C++? Commented Jan 23, 2015 at 16:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
This is not an answer to the question... :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.