Re: Dynamic buffer library



Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx> writes:

Andrew Poelstra schrieb:
"Spiros Bousbouras" <spibou@xxxxxxxxx> writes:

From the code it seems that your intention is to store
the "items" starting at buf[3]. Are the items of type
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.

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
.



Relevant Pages

  • memsize() for the poor (code review request, was: substitute for string 0 termination)
    ... Michael Mair wrote: ... >> Now suppose sizeofis 4, and ints must be properly aligned on ... > it but it is feasible and can be implemented in standard C. ... Compile with -DTEST/#define TEST for some basic tests. ...
    (comp.lang.c)
  • Re: History of far memory...?
    ... Michael Mair wrote: ... >> farmalloc, far char pointers, etc., to differentiate it from near memory. ... Treat it as obsolete and try to get another one. ... It is of course not standard. ...
    (comp.lang.c)
  • Re: offset of a member inside a structure
    ... > Michael Mair wrote: ... apart from the fact that the standard headers can of course ... I would use offsetof. ...
    (comp.lang.c)
  • Re: Is FALSE == 0?
    ... Michael Mair writes: ... > The standard is available for about 270 USD as paper copy or from ... Use google to obtain it. ...
    (comp.lang.c)