>>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
it all depends on your alignment on the CPU in many cases as well.
<snip>
> #define OffsetOf(type, member) ((UInt32) &(((type *) 0)->member))
>
> So in your example above, you would use OffsetOf(MyStruct, finalField) in
> place of sizeof(MyStruct) throughout your code for accurate, predictable
> results. "It's A Good Thing." -- Martha Stewart
this will tell you how large the structure definition you have declared
is, however if you want to know how much data is being stored in that
array, you may wish to check how much memory is being occupied by the
pointer reference "finalField".
the true size (including the array) would be:
OffsetOf(MyStruct,finalField) + // the stuff before the "array"
MemPtrSize(struct.finalField); // the array that size is unknown
but then again, it all depends on how well the MemPtrSize() function
works in this case.. if this does not work (i would not be surprised)
then you can always have an extra field in the structure saying how
large the array is?
i could be wrong :)
cheers.
az.
--
Aaron Ardiri
Java Certified Programmer http://www.hig.se/~ardiri/
University-College i G�vle mailto:[EMAIL PROTECTED]
SE 801 76 G�vle SWEDEN
Tel: +46 26 64 87 38 Fax: +46 26 64 87 88
Mob: +46 70 656 1143 A/H: +46 8 668 78 72
if you enjoy it, then it aint work :) - rule #106 of life
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html