在用gdb调试一些C代码时,我遇到了一些以前从未见过或听说过的事情!编译器(gcc-O0)似乎创建了一种新类型,用于将向量数组传递给函数。。。我想!请查看下面的代码和gdb信息:
/* The Vector type - nothing unusual */
typedef struct {
float x,y,z;
} Vector;
/* The function I was debugging.
* The second parameter is what seems to have changed */
extern void gui_shader_draw(
guiShader *shader,
Vector quad[ 4 ], // << This is the one!
Vector origin,
Vector rotation,
Vector scale,
bool focus,
int mode );
break shader.c:248
Breakpoint 1 at 0x80013ac0: file src/gui/shader.c, line 248.
(gdb) continue
Continuing.
// I have split the next line
Breakpoint 1, gui_shader_draw (
shader=0x80588ea8,
quad_t=0x80585fe8, // << What the?
origin=...,
rotation=...,
scale=...,
focus=false,
mode=3) at src/gui/shader.c:249
// The values quad_t points to are all good
(gdb) print quad_t[0]
$10 = {x = -320, y = -240, z = 0}
(gdb) print quad_t[1]
$11 = {x = 320, y = -240, z = 0}
(gdb) print quad_t[2]
$12 = {x = 320, y = 240, z = 0}
(gdb) print quad_t[3]
$13 = {x = -320, y = 240, z = 0}
编辑1:我必须指出,代码编译和工作良好。与其他变量或类型quad_t没有冲突,我只是好奇GCC做了什么以及为什么。
extern void gui_shader_draw(
guiShader *shader,
Vector quad_t[ 4 ],
Vector origin,
Vector rotation,
Vector scale,
_Bool focus,
int mode
);
不过,预处理器输出中没有名为“quad_t”的typedef。但是我在sys/types.h中找到了这个(在-d'oh!之前我错过了)
/usr/include$ find . | xargs grep -s quad_t
./sys/types.h:typedef __uint64_t u_quad_t;
./sys/types.h:typedef __int64_t quad_t;
./sys/types.h:typedef quad_t * qaddr_t;
./sys/types.h:# define quad quad_t // << There you are!