我有C/C++背景。我通常在代码中添加大量断言,而在C或C++中,没有保证可以消除子表达式的求值(即断言参数)。所以我不得不使用宏。
在C#中,我没有那个级别的宏支持。但是我有Conditional属性。根据我对C和C++的经验,由于副作用,不能消除子表达式。
例如,
[Conditional(DEBUG)]
void func1(int a)
{
// Do something.
}
int func2()
{
// Will this be called?
}
func1(func2());
如果还在调用func2,我应该像isDebugMode() &&am
换句话说,如何根据宏的先前定义重新定义宏?具体来说,我想在C++中将一个字符串添加到字符串宏的末尾。这就是我迄今为止尝试过的:
#define FOO "bla"
// code here will read FOO as "bla"
#define FOO FOO ## "dder"
// code here will read FOO as "bladder"
在C++中,这将返回error: FOO was not declared in this scope。如果没有这个错误,我怎么做呢?
编辑:我已经阅读了评论,发现了什
我在我的遗留代码中有这样的代码
#define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y)
该bean在应用程序中使用了分配,现在我尝试在freeBSD中对其进行编译,并不断得到:
/usr/include/c++/4.2/bits/istream.tcc:123:35: error: macro "min" requires 2 arguments, but only 1 given
/usr/include/c++/4.2/bits/istream.tcc:124:45: err
我见过这样的密码:
#define A // macro
A void foo(bar); // function declaration
这是:
#define B // macro
class B foo { // class declaration
bar
};
在那里使用宏意味着什么?
呃.我是说我不懂语法。我以前没见过这个。
事实上,我只是在opencv3.1中的features2d.hpp中找到了这类代码。
class CV_EXPORTS_W BOWImgDescriptorExtractor {
...
CV_WRAP void setVocabulary( const M