At 1:18 PM -0500 2/14/00, [EMAIL PROTECTED] wrote:
>typedef struct
>{
>        Byte n;
>        UInt i;
>        char text[1];
>} PackedStruct
>
>...
>
>What I do when I need to know the amount of memory to allocate for a packed struct is 
>something like
>
>memneeded = (sizeof(PackedStruct) - 1) + StrLen(str1) + StrLen(str2) + ... + 
>numstrings;
>
>The -1 takes off the size of the single char placeholder at the end of the struct, 
>and numstrings accounts for null terminators on each string.

Here's a question for all you C gurus out there: What is the size of a struct that 
contains an unbounded array? This is the only question about C I couldn't find the 
answer to in Harbison & Steele's book.

typedef struct
{
        ...
        SomeType finalField[];
} MyStruct

... sizeof(MyStruct) ...

So what is the size of this struct? The answer, in practice, seems to be that the 
final field is considered to be of size zero. (Of course, there can be padding before 
the final field, but that isn't the issue.) I have never seen a book on C that 
explains this. Perhaps this is why some programmers use char text[1] instead of char 
text[]?
-
Danny Epstein - Applied Thought
No Palm is an Island - try BeamBooks
http://www.appliedthought.com/beambooks

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to