Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Structures of indefinite size

Reply
Thread Tools

Re: Structures of indefinite size

 
 
Dave Thompson
Guest
Posts: n/a
 
      06-26-2003
On Fri, 20 Jun 2003 10:22:05 -0400, Eric Sosman <(E-Mail Removed)>
wrote:

> 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 worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any support for indefinite length integer PengYu.UT@gmail.com C++ 6 03-30-2006 05:28 PM
indefinite number of arguments PengYu.UT@gmail.com C++ 3 03-27-2006 06:05 AM
Session timeout indefinite =?Utf-8?B?T2xlZw==?= ASP .Net 1 12-09-2005 04:13 PM
structures, structures and more structures (questions about nestedstructures) Alfonso Morra C Programming 11 09-24-2005 07:42 PM
Indefinite for loop syntax question Jenny Java 5 09-16-2004 11:06 AM



Advertisments