Velocity Reviews

Velocity Reviews (
-   C Programming (
-   -   Re: Structures of indefinite size (

Dave Thompson 06-26-2003 03:17 AM

Re: Structures of indefinite size
On Fri, 20 Jun 2003 10:22:05 -0400, Eric Sosman <>

> Ben Pfaff wrote:
> >
> > That said, the idea of including a variable-length array in a C
> > structure has a long and spotted history. The typical way to do
> > it in C90 is [struct hack ...] In C99, [FAM...]

> A third method that works with both C90 and C99 is
> to omit the `text' part of the struct altogether and just
> rely on the knowledge that the characters follow the
> struct. A macro can hide the details:
> struct string {
> unsigned short capacity;
> unsigned short length;
> };
> #define TEXT(stringptr) (char*)((stringptr) + 1)

Just to note: this method is only guaranteed to work for (the three
flavors of) char, because they cannot have nontrivial alignment; it
can be adjusted for other types, but not as easily as the struct-hack
or FAM methods. The OP did ask for strings (which must be char, or
maybe wchar_t) although the subject line is phrased more generally.

- David.Thompson1 at

All times are GMT. The time now is 10:59 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.