Tuesday 15 March 2011

c++ - C macro to transform a SVN revision to an integer -


I'm looking for a C / C + + macro that reads "$ Amendment: 9 $" or "$ Amendment : 9999999 $ "in an integer or string

I know that this is present to achieve simple tasks, but I want to do it at compile time.

My wish is to write things like this: unsigned int rev = SVN_TO_INT ("$ revision $");

I agree that you can use the macros or templates through the timing of the wire Can not work with So ... do not use the wire.

This is an ugly hack, but I think it meets all your needs. I do not recommend it.

#define $ modification structure REV_STR {unsigned foo #define $ * 64; }; $ Amendment: $ 4521 enum {REV = sizeof (REV_STR) / 8}; #undef $ Modification #undef $ #include & lt; Iostream & gt; Int main () {std :: cout & lt; & Lt; REV & LT; & Lt; Std :: endl; Return 0; } // $ g ++ -Wall -Wextra revision.cpp & amp; Amp; ./a.exe // revision.cpp: 4: WARNING: The width of `REV_STR :: foo 'is greater than that of / / 4521

No comments:

Post a Comment