Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #7077

Re: packing a "variable length struct"

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: packing a "variable length struct"
Date 2011-06-27 09:06 -0700
Organization None to speak of
Message-ID <ln7h879s42.fsf@nuthaus.mib.org> (permalink)
References <739a8aed-13cb-4cb4-9ac0-0e360bcef865@bl1g2000vbb.googlegroups.com> <iu9pb0$vtl$1@dont-email.me>

Show all headers | View raw


Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> On 6/27/2011 5:46 AM, fishboy wrote:
>> [...]
>>    void *buffer = malloc(szA + szC);
>>
>>    memcpy(buffer,&(B->meta), szA);
>>    memcpy(buffer+szA, B->centres, szC);
>
>      In addition to the points others have made, note that
> arithmetic on `void*' (more generally, on any `incomplete_type*')
> is forbidden.  Pointer arithmetic takes into account the size of
> the thing pointed to; if the size is unknown, as for `void*', the
> arithmetic cannot be performed.

And if you use gcc in its default mode, it won't warn you about this;
gcc supports void* arithmetic as a non-conforming extension.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

packing a "variable length struct" fishboy <j.j.fishbat@gmail.com> - 2011-06-27 02:46 -0700
  Re: packing a "variable length struct" Ian Collins <ian-news@hotmail.com> - 2011-06-27 22:48 +1200
  Re: packing a "variable length struct" Alexander Bartolich <alexander.bartolich@gmx.at> - 2011-06-27 11:01 +0000
    Re: packing a "variable length struct" James Kuyper <jameskuyper@verizon.net> - 2011-06-27 07:19 -0400
      Re: packing a "variable length struct" Shao Miller <sha0.miller@gmail.com> - 2011-06-27 14:12 -0400
        Re: packing a "variable length struct" Shao Miller <sha0.miller@gmail.com> - 2011-06-27 15:08 -0400
        Re: packing a "variable length struct" Alexander Bartolich <alexander.bartolich@gmx.at> - 2011-06-27 20:09 +0000
          Re: packing a "variable length struct" Shao Miller <sha0.miller@gmail.com> - 2011-06-27 17:45 -0400
  Re: packing a "variable length struct" Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-27 07:24 -0400
    Re: packing a "variable length struct" Keith Thompson <kst-u@mib.org> - 2011-06-27 09:06 -0700
      Re: packing a "variable length struct" BGB <cr88192@hotmail.com> - 2011-06-27 15:35 -0700
    Re: packing a "variable length struct" fishboy <j.j.fishbat@gmail.com> - 2011-06-30 23:54 -0700

csiph-web