在Google V8项目中读取globals.h时遇到以下宏定义.
// The expression ARRAY_SIZE(a) is a compile-time constant of type
// size_t which represents the number of elements of the given
// array. You should only use ARRAY_SIZE on statically allocated
// arrays.
#define ARRAY_SIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
Run Code Online (Sandbox Code Playgroud)
我的问题是后半部分:static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))).我想到的一件事是:由于后一部分将始终求1值为(类型)size_t,整个表达式将被提升为size_t.
如果这个假设是正确的,那么还有另一个问题:由于sizeof运算符的返回类型是size_t,为什么需要这样的推广?以这种方式定义宏有什么好处?
可能重复:
'unsigned temp:3'表示什么
我在阅读Clang的代码时遇到了一个问题.
class LangOptions {
public:
unsigned Trigraphs : 1; // Trigraphs in source files.
unsigned BCPLComment : 1; // BCPL-style '//' comments.
...
};
Run Code Online (Sandbox Code Playgroud)
这是我第一次看到语法":1",":1"代表什么?谢谢!
当我用gcc-4.6.3或gcc-4.7.2编译这个程序时,编译器给出了一个关于重载调用不明确的错误:
#include <iostream>
#include <functional>
class Scott
{
public:
void func(const bool b = true)
{
std::cout << "Called func() with a boolean arg" << std::endl;
}
void func(std::function<void(void)> f)
#ifdef WITH_CONST
const
#endif
{
std::cout << "Called func() with a std::function arg" << std::endl;
}
};
int main (int argc, char *argv[])
{
Scott s;
s.func([] (void) { });
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我使重载函数const,它编译很好并调用我没想到的方法!
devaus120>> g++ -Wall -std=c++11 -DWITH_CONST wtf.cxx
devaus120>> ./a.out
Called func() with a boolean arg
Run Code Online (Sandbox Code Playgroud)
所以,我有两个问题:
TIA. …
阅读这个简单的bash函数后,我有点困惑:
log_daemon_msg() {
if [ -z ${1:-} ]; then
return 1
fi
echo $@
}
Run Code Online (Sandbox Code Playgroud)
根据man 1 bash,说:
$ {参数:-word}
Run Code Online (Sandbox Code Playgroud)Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
如果$1为NULL或未设置,则值为$1NULL.这就是我的困惑来自:为什么有必要为$ 1分配NULL值,即使事实$1为NULL或未设置已知?如果我的理解是错误的,请纠正我.谢谢!
我正在尝试删除BST中有两个子节点的节点.例如,
|
12
/ \
5 15
/ \ \
2 6 20
Run Code Online (Sandbox Code Playgroud)
我想删除包含info = 12的节点.我需要帮助才能执行此操作.