• <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).

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

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

            久久婷婷国产麻豆91天堂| 无码人妻少妇久久中文字幕| 国内精品人妻无码久久久影院导航| 一本色道久久99一综合| 九九99精品久久久久久| 久久国产一片免费观看| 亚洲∧v久久久无码精品| 欧洲性大片xxxxx久久久| 99久久久精品| 亚洲国产视频久久| 91精品国产色综久久| 久久久久久精品免费免费自慰| 青青热久久综合网伊人| 久久青青色综合| 久久久精品久久久久特色影视| 久久亚洲中文字幕精品有坂深雪| 99久久精品无码一区二区毛片 | 亚洲国产精品无码成人片久久| 94久久国产乱子伦精品免费| 午夜欧美精品久久久久久久| 人妻中文久久久久| 久久国产成人午夜AV影院| 国内精品久久久久影院一蜜桃| 久久久久国产| 久久国产精品免费一区二区三区| 欧洲精品久久久av无码电影| 麻豆精品久久久久久久99蜜桃| 久久久久亚洲?V成人无码| 久久综合欧美成人| 久久美女人爽女人爽| 99久久99久久| 久久青青草原国产精品免费| 99久久久国产精品免费无卡顿| 日产精品99久久久久久| 亚洲国产精品无码久久久蜜芽 | 蜜臀久久99精品久久久久久| 久久99精品久久久久久齐齐| 精品久久久无码中文字幕| 国产午夜精品理论片久久| 精品久久久久久无码人妻蜜桃| 7国产欧美日韩综合天堂中文久久久久 |