Container_of() 未编译
List.h 定义了一个名为list_entry 的宏,它是container_of() 函数的包装器。 一个优雅的函数,看起来非常精致:
考虑这段代码:
tmp = list_entry(pos,(struct Order),ord_Queue);
当我使用 gcc 编译它时,不断弹出预期表达式的错误。
我的结构定义为:
struct Order
{
double idNum;
char* entryTime;
char* eventTime;
struct list_head ord_Queue;
};
当 Arg2 和 Arg3 中使用了多余的括号时,container_of 似乎存在问题,并且仅应为 Arg1 提供一个括号礼貌 此处 。我已经尝试过,但它不起作用。
一些帮助将不胜感激。
List.h defines a macro called list_entry which is a wrapper for container_of() function.
An elegant function, which seems very delicate:
Consider this piece of code:
tmp = list_entry(pos,(struct Order),ord_Queue);
When I compile it using gcc, a constant error of expected expression is popping up.
My structure is defined as:
struct Order
{
double idNum;
char* entryTime;
char* eventTime;
struct list_head ord_Queue;
};
It seems there is a problem with container_of when there are superfluous brackets used in Arg2 and Arg3, and there should be one bracket only for Arg1 courtesy here . I have tried it, but it doesnt work.
Some help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许当您从内核复制
list.h
时存在错误? (假设您正在此处执行用户空间程序。)因为您的示例代码(稍微剥离一点)确实使用已知良好的实现进行编译。Maybe there is an error in
list.h
when you copied it from the kernel? (Assuming you are doing a userspace program here.) Because your example code (stripped a little more) does compile with a known-good implementation.我相信您还缺少包含“offsetof”宏,该宏由container_of()内部使用。尝试包含以下代码(而不是包含整个 list.h )。
并且不需要在第二个参数中添加额外的括号,没有它它应该可以正常工作。
我希望这应该有效。
I believe that you are missing the inclusion of "offsetof" macro as well, which is used by container_of() internally. Try including following code (instead of including whole list.h.
And there is no need of adding extra parenthesis in 2nd argument, it should work fine without it.
I hope this should work.