Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: packing a "variable length struct" |
| Date | 2011-06-27 07:24 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iu9pb0$vtl$1@dont-email.me> (permalink) |
| References | <739a8aed-13cb-4cb4-9ac0-0e360bcef865@bl1g2000vbb.googlegroups.com> |
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.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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