C语言typeof用法报错,求指导

Python012

C语言typeof用法报错,求指导,第1张

Work.Wells 是个 PWellList 类型

根据:typedef TWellList* PWellList

转换下,那就是:TWellList * 类型,即 TWellList 的指针。

就是说,*(TWork.Work) 才是 TWellList ,

所以, (*(TWork.Work))[1] == TWellList[1] ==(struct TWellData * ).

typeof关键字是C语言中的一个新扩展。只要可以接受typedef名称,Sun Studio C 编译器就可以接受带有typeof的结构,包括以下语法类别: 声明 函数声明符中的参数类型链表和返回类型 类型定义 类型操作符s sizeof操作符 复合文字 typeof实参 编译器接受带双下划线的关键字:__typeof和__typeof__。本文中的例子并没有遵循使用双下划线的惯例。从语句构成上看,typeof关键字后带圆括号,其中包含类型或表达式的名称。这类似于sizeof关键字接受的操作数(与sizeof不同的是,位字段允许作为typeof实参,并被解释为相应的整数类型)。从语义上看,typeof 关键字将用做类型名(typedef名称)并指定类型。 使用typeof的声明示例 下面是两个等效声明,用于声明int类型的变量a。 typeof(int) a/* Specifies variable a which is of the type int */ typeof('b') a/* The same. typeof argument is an expression consisting of character constant which has the type int */以下示例用于声明指针和数组。为了进行对比,还给出了不带typeof的等效声明。 typeof(int *) p1, p2/* Declares two int pointers p1, p2 */int *p1, *p2typeof(int) * p3, p4/* Declares int pointer p3 and int p4 */int * p3, p4typeof(int [10]) a1, a2/* Declares two arrays of integers */int a1[10], a2[10]如果将typeof用于表达式,则该表达式不会执行。只会得到该表达式的类型。以下示例声明了int类型的var变量,因为表达式foo()是int类型的。由于表达式不会被执行,所以不会调用foo函数。 extern int foo()typeof(foo()) var使用typeof的声明限制 请注意,typeof构造中的类型名不能包含存储类说明符,如extern或static。不过允许包含类型限定符,如const或volatile。例如,下列代码是无效的,因为它在typeof构造中声明了extern: typeof(extern int) a下列代码使用外部链接来声明标识符b是有效的,表示一个int类型的对象。下一个声明也是有效的,它声明了一个使用const限定符的char类型指针,表示指针p不能被修改。 extern typeof(int) btypeof(char * const) p = "a"在宏声明中使用typeof typeof构造的主要应用是用在宏定义中。可以使用typeof关键字来引用宏参数的类型。因此,在没有将类型名明确指定为宏实参的情况下,构造带有所需类型的对象是可能的。

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中。可以跨平台。