Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Oct 1998 00:04:27 +0100
From:      Eivind Eklund <eivind@yes.no>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: questions of taste..  mbuf header change
Message-ID:  <19981027000427.59289@follo.net>
In-Reply-To: <199810261712.MAA19008@khavrinen.lcs.mit.edu>; from Garrett Wollman on Mon, Oct 26, 1998 at 12:12:55PM -0500
References:  <199810252219.RAA10102@whizzo.transsys.com> <199810261712.MAA19008@khavrinen.lcs.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Oct 26, 1998 at 12:12:55PM -0500, Garrett Wollman wrote:
> (You have stumbled into one of the most annoying misfeatures of the C
> language: there is no way to actually USE an incomplete structure that
> is even marginally useful; in order to have opaque objects it is
> necessary to insert a level of indirection which is less than
> desirable in a low-level context such as this.)

Well, there is one nasty trick: Create a non-opaque definition of a
variable as an anonymous structure, then fill in a char[] with the
size of the structure, minus the size of the first element (which you
need to get the correct alignement).  Like this:

struct something;

static struct {
	struct something *something;
	... more struct defintion here ...
} anonymous_stuff;

struct stuff {
	struct something *do_not_use_this_under_any_circumstance;
	char filler[sizeof(anonymous_stuff) - sizeof(anonymous_stuff.something)];
};

This is not allowed to fail in standard C.  However, it may well
produce a bunch of warnings, and I don't particularly like it.  It
will make any cross-file checker (like a good lint) SCREAM (at least
until you set up the necessary filters for those warning messages).

Eivind.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19981027000427.59289>