• <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)  編輯 收藏 引用

            久久综合久久综合九色| 精品国产综合区久久久久久| 久久一日本道色综合久久| 亚洲伊人久久综合中文成人网| 18岁日韩内射颜射午夜久久成人| 国产精品久久久久aaaa| 青青草国产成人久久91网| 久久精品视频免费| 亚洲国产天堂久久久久久| 久久99精品国产麻豆宅宅| 中文无码久久精品| 亚洲狠狠久久综合一区77777| 91亚洲国产成人久久精品网址| 久久久精品波多野结衣| 久久99热这里只有精品66| 久久夜色精品国产噜噜噜亚洲AV| 精品午夜久久福利大片| 久久伊人亚洲AV无码网站| 日产精品久久久久久久| 精品久久国产一区二区三区香蕉| 亚洲精品第一综合99久久 | 久久91精品综合国产首页| 无码8090精品久久一区| 久久久久久无码Av成人影院| 成人资源影音先锋久久资源网| 久久久精品国产亚洲成人满18免费网站| 久久精品青青草原伊人| 国产亚洲成人久久| 国产亚洲美女精品久久久久狼| 一级做a爰片久久毛片看看| 国产欧美久久一区二区| 伊人久久大香线焦AV综合影院| 精品久久久久久无码国产| 国产精品久久久久久福利漫画| 2021最新久久久视精品爱 | 亚洲午夜久久久久妓女影院| MM131亚洲国产美女久久| 一级女性全黄久久生活片免费 | 久久超乳爆乳中文字幕| 蜜臀久久99精品久久久久久| 日韩乱码人妻无码中文字幕久久|