• <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 閱讀(182) 評論(0)  編輯 收藏 引用

            伊人久久精品线影院| 久久久精品国产免大香伊| 精品久久久久久久| 91久久精品国产免费直播| 久久93精品国产91久久综合| 久久精品99无色码中文字幕| 精品久久久一二三区| 97久久天天综合色天天综合色hd| 久久国产精品偷99| 狠狠色丁香久久婷婷综合| 99久久精品国产一区二区| 久久99热这里只有精品66| 99久久精品免费观看国产| 亚洲精品国产美女久久久| 久久久久人妻一区精品| 成人综合伊人五月婷久久| 99久久国产亚洲综合精品| 亚洲综合婷婷久久| 性高湖久久久久久久久| 日韩电影久久久被窝网| 久久久91精品国产一区二区三区| 精品久久久久久中文字幕大豆网| 99久久成人18免费网站| 久久久久亚洲AV片无码下载蜜桃| 日韩中文久久| 香蕉aa三级久久毛片| 中文精品久久久久国产网址| 97久久久久人妻精品专区| 久久精品国产99久久久古代| 亚洲伊人久久综合中文成人网| 国产成人久久久精品二区三区 | 国产精品欧美久久久天天影视| 伊人久久亚洲综合影院| 免费精品久久久久久中文字幕| 97精品国产97久久久久久免费| 青青草原综合久久| 99精品国产在热久久| 久久se精品一区精品二区| 国内精品久久久久久野外| 无码人妻久久久一区二区三区 | 久久精品国产免费|