您的位置:首页 > 其它

数组原来还可以这样初始化【转】

2008-10-31 13:57 579 查看
数组原来还可以这样初始化:[0 ... LMAP_ENTRIES-1] = { "gliethttp

http://blog.chinaunix.net/u1/38994/showart_1334369.html
#include <stdio.h>
#include <string.h>

#define LMAP_ENTRIES 100
struct lmap {
    const char *name;
    void *data;
};
struct luther_gliethttp {
    struct lmap lmap[LMAP_ENTRIES];
    const char *name;
};

static struct luther_gliethttp luther = {
    .lmap = {
        [0 ... LMAP_ENTRIES-1] = { "gliethttp", NULL }
    },
    .name = "luther",
};
int main(int argc, char *argv[])
{
    int i;
    for (i = 0; i < LMAP_ENTRIES; i++) {
        printf("luther.lmap[%d].name = %s/n", i, luther.lmap[i].name);
    }
    printf("%p/n", ((unsigned int)(0x01 << ((sizeof(int) * 8) - 1)) - 1));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct null