【发布时间】:2013-10-23 20:05:02
【问题描述】:
我有一个包含两个整数的struct。
struct ref{
int next;
int marked;
}
我需要使用 CAS 原子地比较其中两个结构。
__sync_bool_compare_and_swap(&(ref1),old,new);
我如何转换这个struct 以便在c 中将其引用为long long?
我试过了:
__sync_bool_compare_and_swap(&((long long)(ref1)),(long long)(old),(long long)(new));
但它给了我这个错误:
aggregate value used where an integer was expected
【问题讨论】:
-
类似于 * (( long long* ) &ref1) 的东西?
-
Casting struct into int 的可能重复项
-
过去在 IBM 被称为“U 字”。
-
你能说“联合”吗?当然可以。