【发布时间】:2015-10-14 15:15:15
【问题描述】:
假设大约每第四次构建我想生成编译器警告,可能使用#warning 或者可能有条件地声明应该生成溢出警告的int x = 3.14; 之类的东西。
我怎么能做到这一点,只使用前身?
其中一些问题看起来不错,但我看不出如何生成 4 和 4 之间的随机数或取它们生成的大数的模数:
How can I generate unique values in the C preprocessor?
How to generate a series of random numbers with the C/C++ preprocessor
Generate a random number using the C Preprocessor
[更新] 我忘了说我受限于 C++ 2003 :-(
我从Generate a random number using the C Preprocessor 那里得到答案并添加了
#if KISS / 4 == 1
#warning Danger, Will Robinson!
#endif
然后我明白了
../test/main.cpp:105:5: error: token "=" is not valid in preprocessor expressions
参考线
#if KISS / 4 == 1
KISS 扩展为
(((((z=36969*(z&65535)+(z>>16))<<16)+((w=18000*(w&65535)+(w>>16))&65535))^(jcong=69069*jcong+1234567))+(jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5)))
所以,看来我需要一个不同的解决方案
【问题讨论】:
-
你能透露
main.cpp的第105行吗?
标签: c++ g++ c-preprocessor c++03