On 07/23/11 04:21, Bruce Evans wrote:

C didn't support support variable-sized structs before C99, and
doesn't really support them now.  Various hacks are used to make
pseudo-structs larger or smaller than ones that can actually be
declared work.  The above is one.  The pseudo-struct is malloc()ed
and has size larger than the declared one.  The above says what
would be in it if it could be declared.

If this were written in C99, it might declare u_char ar_foo[] in the
the code instead of in a comment.  But C can't really support variable-
sized structs.  It only allows one ar_foo[], which must be at the end
of the struct.  ar_foo then has a known offset but an unknown size.
The other ar_bar[]'s still can't be declared, since they want to be
further beyond the end of the struct, which places them at an unknown
offset.

A probably-less-unportable way was to declare everything in the struct
but malloc() less.  This only works if all the magic fields are at
known offsets.  This doesn't work in the above, since the fields want
to have variable lengths each and thus end up at variable offsets.
Such fields can be allocated from a single larger field (usually an
an array), but you lose the possibility of declaring them all.

Bruce

I got the idea with "dynamic size", tnx:) But comment_only ...ah nevermined. Tnx for explanation, Bruce.
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[email protected]"

Reply via email to