Subject: Re: CMSG_* problems
To: None <tech-userlevel@NetBSD.org, tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
Date: 02/12/2007 17:07:23
>> Knowing what "the maximally aligned type" *is* is machine- and/or
> Except that CMSG_* will not be returning a double or float.
You don't know that. I don't know that. At present it won't, because
none of the current interfaces do, but there's no way to promise that
for all time.
> And it really isn't compiler dependent since C mandates that
> alignment for char <= short <= int <= long <= long long. So using
> long long wouldn't be machine or compiler-dependent.
But it is, because there could be other types requiring even stricter
alignment. (Nothing promises that, for example, long long alignment is
sufficient for pointers.)
> What I am saying CMSG_* is sufficient if you specify an aligned
Sufficient? Perhaps. But unclean and ugly. I really dislike actually
encouraging pointer punning (by not providing an interface that permits
doing it correctly any other way).
> and the mechanism for that is not onerous.
That's a matter of opinion, and we obviously disagree on it. But if
the interface stands, it *really* needs to explicitly call out that the
buffer needs to be aligned; that is not documented anywhere at present
as far as I can see, unless you happen to be C wizard enough to infer
it from the documented interfaces.
> I think you are making a mountain out of molehill.
Perhaps. I saw an ugly interface and proposed cleaning it up. If you
disagree about the aesthetics, or disagree about the importance of the
aesthetics, well, then, perhaps I am.
I just know that in my experience, the cleaner the code is, the easier
it is to keep a lid on its bugs. This includes extremely strict
type-correctness in many respects, such as const poisoning,
-Wmissing-prototypes -Wstrict-prototypes...and copying control message
headers out of the buffer into struct cmsghdr objects rather than
overlaying the objects onto the buffer. Getting the alignment right
without making fragile assumptions is just asking for too much trouble.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML firstname.lastname@example.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B