• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ++wythern++

            X presents Y for a better Z

            Usage of zero element array

            Source: http://stackoverflow.com/questions/4255193/declaring-zero-size-vector

            This is called a flexible array member, and in C99 is written as char bar[];, and in C89 was written as char bar[1];, and which some compilers would let you write as char bar[0];. Basically, you only use pointers to the structure, and allocate them all with an amount of extra space at the end:

            const size_t i = sizeof("Hello, world!");
            struct foo *p = malloc(offsetof(struct foo, bar) + i);
            memcpy(p->bar, "Hello, world!", i);
            // initialize other members of p
            printf("%s\n", p->bar);

            That way, p->bar stores a string whose size isn't limited by an array declaration, but which is still all done in the same allocation as the rest of the struct (rather than needing the member to be a char * and need two mallocs and two frees to set it up).

            好處:連續(xù)(虛擬)內(nèi)存空間以及僅需一次的free操作。

            posted on 2011-05-04 13:37 wythern 閱讀(184) 評論(0)  編輯 收藏 引用

            久久综合狠狠色综合伊人| 欧美粉嫩小泬久久久久久久 | 日韩人妻无码精品久久免费一| 亚洲天堂久久久| 三上悠亚久久精品| 久久久久国产一区二区三区| 久久精品日日躁夜夜躁欧美| av无码久久久久久不卡网站| 久久亚洲欧洲国产综合| 无码国内精品久久人妻蜜桃| 国产精品永久久久久久久久久 | 青春久久| 久久91精品国产91久久麻豆| 18禁黄久久久AAA片| 国产精品久久国产精品99盘 | 日韩va亚洲va欧美va久久| 久久国产色AV免费看| 亚洲精品成人网久久久久久| 久久久久久国产精品免费无码| 久久综合一区二区无码| 亚洲天堂久久精品| 亚洲AV无码一区东京热久久| 婷婷久久综合| 久久嫩草影院免费看夜色| 久久久久久久尹人综合网亚洲 | 无码精品久久一区二区三区| 久久福利青草精品资源站| 狼狼综合久久久久综合网| 精品久久久无码人妻中文字幕| 久久亚洲国产成人精品无码区| 久久这里只有精品首页| 91精品国产高清91久久久久久| 久久婷婷五月综合97色一本一本 | 少妇人妻综合久久中文字幕| 综合久久给合久久狠狠狠97色| 久久久久成人精品无码| 久久久久女教师免费一区| 国产精品欧美亚洲韩国日本久久| 7国产欧美日韩综合天堂中文久久久久| 男女久久久国产一区二区三区| 久久久一本精品99久久精品88|