
STL好办,
struct node_base
{
node_base* next;
node_base* prev;
};
template<typename T>
struct node : public node_base
{
T value;
};
> <http://hiphotos.baidu.com/joec3/pic/item/c9a13b12cfa67fe5c2fd7853.jpg>
>
> 也许是我理解的不到位,谁能给我解释下这个为什么需要中间变量__mptr?
康神的一段类似的代码被不明真相的小盆友"优化"掉了这段赋值,发生过严重的问题。
Joe 提到的这个宏,除了类型检查,主要也是为了避免这个问题,比如
container_of(find_the_ptr_with_side_effect(my_ptr), type_name,
member_name);
如果的 find_the_ptr_with_side_effect() 存在 side effect 的话,就可能导致问题。
半夜睡之前发的,真没注意,因为习惯性的我都会这么写。
min 的 (void) (&_x == &_y) 这个也的确是为了做类型检查,不过如果不是为了避免被多次展开,直接用 x 和 y 也是可以
的。