Re: Dynamic buffer library
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 20:13:32 +0200
Andrew Poelstra schrieb:
Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx> writes:
Andrew Poelstra schrieb:
"Spiros Bousbouras" <spibou@xxxxxxxxx> writes:
the "items" starting at buf[3]. Are the items of typeFrom the code it seems that your intention is to store
size_t ? If not how do you know that buf[3] is properly
aligned ?
The items may not be of size_t. I don't know that they're properly
aligned (this is an example of the UB I knew that I missed). What
would be the best way for me to guarantee alignment? Am I going to
need to use a union?
There is no portable way that does all the work; some time ago,
I wrote a "memsize" solution that does store the size in a standard
conforming albeit ugly and wasteful way. I asked for a code review
back then but did not receive any response; you are welcome to take
out the useful part of the ideas:
<3649apF4s752rU1@xxxxxxxxxxxxxx>
Download seems still possible.
Thanks! That'll be useful, and probably end up being my solution.
A quick question, though, is struct padding consistant?
That is, for every struct { int x, size_t y, float z }, will (&z - &x)
always be the same number? Because if so, a more efficient solution
could be found.
If you always use the same identifiers for members of structs
with this layout and this sequence of types in your source: Yes
(see "compatible type" in the standard).
If not: The standard does not guarantee it but in every
implementation worth its salt, yes.
Read the bits about compatible types w.r.t. structure types and
about the "common initial sequence" for unions in the standard
to get a feeling about what is guaranteed (C90 or C99).
The DS900x series probably uses a member name based struct layout
for struct types not used in a union...
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.
- References:
- Dynamic buffer library
- From: Andrew Poelstra
- Re: Dynamic buffer library
- From: Spiros Bousbouras
- Re: Dynamic buffer library
- From: Andrew Poelstra
- Re: Dynamic buffer library
- From: Michael Mair
- Re: Dynamic buffer library
- From: Andrew Poelstra
- Dynamic buffer library
- Prev by Date: Re: [Newbie] changing allocated memory
- Next by Date: Re: [newbie] strcpy, strtok and strcat problem...
- Previous by thread: Re: Dynamic buffer library
- Next by thread: Re: Dynamic buffer library
- Index(es):
Relevant Pages
|