1

我有一个struct包含两个整数。

struct ref{
  int next;
  int marked;
}

我需要使用 CAS 原子地比较其中两个结构。

__sync_bool_compare_and_swap(&(ref1),old,new);

我如何才能struct将其转换为long longc 中的 a 引用?

我试过这个:

    __sync_bool_compare_and_swap(&((long long)(ref1)),(long long)(old),(long long)(new));

但它给了我这个错误:

aggregate value used where an integer was expected
4

1 回答 1

-1

假设这ref1是 struct type 的一个实例refold并且new已经是 type long long,您应该能够:

__sync_bool_compare_and_swap((long long *)&ref1, old, new);
于 2013-10-15T21:20:30.183 回答