Date: Tue, 26 Jul 2011 11:13:50 +0400 From: Vladimir Budnev <vladimir.budnev@gmail.com> To: Bruce Evans <brde@optusnet.com.au> Cc: freebsd-net@FreeBSD.org Subject: Re: What does define COMMENT_ONLY mean? Message-ID: <4E2E692E.6050503@gmail.com> In-Reply-To: <20110723100828.S4156@besplex.bde.org> References: <CAAvRK942U%2BAiokN0MWQVteeYS5tk%2BdrCOQ_ybRcKZT0gN4Y8WA@mail.gmail.com> <20110723100828.S4156@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4E2E692E.6050503>