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

            久久精品国产亚洲77777| 久久99国产精品二区不卡| 久久精品国产影库免费看| 亚洲色欲久久久综合网东京热| 国内精品久久久久久久coent| 国产成人精品白浆久久69| 久久久久人妻精品一区二区三区| 国产亚洲精久久久久久无码77777| 要久久爱在线免费观看| 久久久国产视频| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 少妇人妻88久久中文字幕| 亚洲精品99久久久久中文字幕| 久久久久久国产a免费观看不卡 | 99久久精品国产毛片| 国产成人精品久久综合| 精品久久久久久无码中文字幕 | 久久久精品午夜免费不卡| 久久久精品免费国产四虎| 久久高清一级毛片| 99精品国产免费久久久久久下载| 一本久久知道综合久久| 久久这里只有精品首页| 久久久久久av无码免费看大片| 国产91久久精品一区二区| 国产精久久一区二区三区| 精品少妇人妻av无码久久| 伊人久久大香线蕉AV色婷婷色| 久久一区二区三区99| 久久国产精品偷99| 久久国产精品-国产精品| 久久精品毛片免费观看| 亚洲AV无码久久寂寞少妇| 精品久久久久久久久免费影院 | 亚洲精品国产自在久久| 日韩精品无码久久久久久| 国内精品久久久久久不卡影院| 久久亚洲精品无码VA大香大香| 色综合久久中文色婷婷| 久久精品国产亚洲αv忘忧草| 亚洲国产精品久久久久婷婷老年|