我有这个数组:
static const Layout layouts[] = {
{ "[]=", tile },
{ "><>", NULL },
{ "[M]", monocle },
};
这个函数应该循环遍历数组:
int
cyclelayout(const Arg *arg) {
static unsigned short int layout = 0;
if (++layout >= sizeof(layouts)/sizeof(layouts[0])) {
layout = 0;
}
setlayout( &((Arg) {.v = &layouts[layout]}));
}
当它被调用时,它应该设置下一个布局,如果超出数组元素则返回 0。但它会遍历数组元素并且程序崩溃。我想不通怎么了?
参数和布局:
typedef union {
int i;
unsigned int ui;
float f;
const void *v;
} Arg;
typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;