We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hi,各位: 我的代码环境:g++ 4.8.4, Ubuntu 14.04.6,kernel 4.4.0-148-generic 失败的地方是在 src/double_linked_list_demo.cpp 中的代码:
list_for_each_prev(pos, &head){ struct DemoNode * node = list_entry(pos, struct DemoNode, list); printf("%d\n", node->key); } list_for_each_entry(node, &head, list){ printf("%d\n", node->key); }
上面demo 示例,list_for_each_prev 中,list_entry中的type 参数是struct DemoNode, 但在 list_for_each_entry 中使用 typeof(*pos) (也就是decltype(*pos) ) , 它返回的type 为 struct DemoNode& , 也就导致编译失败。我做了下面的简单修复.
其中原来的 list_for_each_entry 的实现
#ifndef _MSC_VER #define list_for_each_entry(pos, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member); \ &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member)) #else #define list_for_each_entry(pos, head, member) \ for (pos = list_entry((head)->next, typeof(pos), member); \ &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(pos), member)) #endif
修复:
#define list_for_each_entry(pos, head, member) \ for (pos = list_entry_ptr((head)->next, typeof(pos), member); \ &pos->member != (head); \ pos = list_entry_ptr(pos->member.next, typeof(pos), member)) #define list_entry_ptr(ptr, ptrtype, member) \ (reinterpret_cast<ptrtype>( \ (char *)(ptr) - (char *)(&(reinterpret_cast<ptrtype>(1)->member)) + 1))
The text was updated successfully, but these errors were encountered:
No branches or pull requests
hi,各位:
我的代码环境:g++ 4.8.4, Ubuntu 14.04.6,kernel 4.4.0-148-generic
失败的地方是在 src/double_linked_list_demo.cpp 中的代码:
上面demo 示例,list_for_each_prev 中,list_entry中的type 参数是struct DemoNode, 但在 list_for_each_entry 中使用 typeof(*pos) (也就是decltype(*pos) ) , 它返回的type 为 struct DemoNode& , 也就导致编译失败。我做了下面的简单修复.
其中原来的 list_for_each_entry 的实现
修复:
The text was updated successfully, but these errors were encountered: