Tag: 标准兼容性

C中的非ASCII字符

我正在查看谷歌go的运行时源代码(在https://go.googlecode.com/hg/src/pkg/runtime/ ),似乎他们使用特殊字符作为其function名称,·。 (例如, 请访问https://go.googlecode.com/hg/src/pkg/runtime/cgocall.c )。 这是否被主要编译器接受? 它不是ANSI C,是吗? 或者它只是一些宏观魔法? 谢谢!

内核的“container_of” – 任何使ISO符合标准的方法吗?

在查看Linux内核的双向链接循环列表的实现时,我发现了以下宏: #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr – offsetof(type,member) );}) 这种方式的工作方式是它返回指向结构的指针,只给出其中一个成员的地址: struct blabla { int value; struct list_head *list; } 因此,只有指向列表的指针,您才能获得指向blabla(并获得“value”)的指针。 对于我的问题,我如何使其尽可能便携(符合C89 / C99的最佳情况?)。 由于使用了typeof(),这只是gcc。 这是我到目前为止所得到的: #define container_of(ptr, type, member) ( \ (type *) (char *)(ptr)-offsetof(type,member)\ ) 这个片段是否符合ISO标准(因此应该能够在任何符合标准的编译器上编译)?