把结构定义成一个数组
今天读 freebsd 的源码时发现一个小技巧,经过同事指点,恍然大悟。原来 C 里面还是有好多东西自己不知道的啊。
typedef struct _jmp_buf { int _jb[_JBLEN + 1]; } jmp_buf[1];
这个是 setjmp.h 里的一行定义,把一个 struct 定义成一个数组。这样,在声明 jmp_buf 的时候,可以把数据分配到堆栈上。但是作为参数传递的时候则作为一个指针。这样和 c array 的表现一样了。
btw, 读 freebsd 的源码后,感觉头文件组织比 vc 的强太多了。
Comments
Posted by: owent | (16) November 27, 2015 12:00 PM
Posted by: 涛 | (15) October 17, 2011 10:55 PM
Posted by: Anonymous | (14) September 18, 2011 08:57 PM
Posted by: Anonymous | (13) September 18, 2011 08:55 PM
Posted by: 云风他爸 | (12) November 21, 2007 12:19 PM
Posted by: gobr | (11) August 26, 2007 04:44 PM
Posted by: 不空 | (10) December 23, 2005 09:40 AM
Posted by: Alpha | (9) December 23, 2005 09:31 AM
Posted by: madlax | (8) December 22, 2005 09:18 PM
Posted by: coder | (7) December 22, 2005 12:30 PM
Posted by: Solstice | (6) December 22, 2005 10:58 AM
Posted by: 阿立 | (5) December 21, 2005 10:21 AM
Posted by: Cloud | (4) December 20, 2005 10:30 PM
Posted by: dawndu | (3) December 20, 2005 09:58 PM
Posted by: ZER0 | (2) December 20, 2005 09:57 PM
Posted by: Atry | (1) December 20, 2005 05:05 PM