我有兩種結構,就像下面:傳遞的結構與gcc內置插件用於原子訪問
template <class T>
struct pointer_t
{
T *ptr;
uintptr_t tag;
};
template <class T>
struct Node
{
T data;
pointer_t<Node<T> > next;
};
,現在我想例如pointer_t<Node<T> > newNext
傳遞給__sync_bool_compare_and_swap()
功能。根據該函數的原型我傳:
__sync_bool_compare_and_swap((unsigned long*) &newTail.ptr->next, oldNext, newNext)
的問題是,如果我不投newNext
到unsigned long
我會得到:
error: ‘struct pointer_t<Node<int> >’ used where a ‘long unsigned int’ was expected
if (__sync_bool_compare_and_swap((unsigned long*) &newTail.ptr->next, newNext, newNext))
,如果我將它轉換爲unsigned長則:
if (__sync_bool_compare_and_swap((unsigned long*) &newTail.ptr->next, (unsigned long) oldNext, (unsigned long) newNext))
我會得到:
error: ‘struct pointer_t<Node<int> >’ used where a ‘long unsigned int’ was expected.
有人可以解釋我,你可以使用__sync_bool_compare_and_swap這兩個結構?
感謝
你爲什麼鑄造'無符號long'當函數想要'長無符號整型'? –
我的錯誤,但我仍然得到了同樣的錯誤鑄造: 無效的類型鑄造... – Moriss
您的結構將太寬,投下64b平臺上。 – Jeff