您的位置首页百科知识

c语言中container_of, typeof, offsetof这些是哪个标准的?

c语言中container_of, typeof, offsetof这些是哪个标准的?

的有关信息介绍如下:

c语言中container_of, typeof, offsetof这些是哪个标准的?

1. container_of是Linux内核中实现的宏,不是C语言的标准函数。不能跨平台。

#define container_of(ptr, type, member) ({ \

const typeof( ((type *)0)->member ) *__mptr = (ptr); \

(type *)( (char *)__mptr - offsetof(type,member) );})

2. typeof是GNU C的扩展,不是ISO标准中的函数。用gcc编译可以跨平台。

3. offsetof是C语言标准库中的宏,定义在头文件stddef.h中。可以跨平台。