Subject: Re: CMSG_* problems
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Matt Thomas <email@example.com>
Date: 02/12/2007 13:07:48
der Mouse wrote:
>>> (The only way I can think of to ensure alignment suitable for a
>>> struct cmsghdr, without machine- or compiler-dependent hackery, is
>>> to allocate the buffer as an array of struct cmsghdr, and that still
>>> doesn't ensure the buffer is suitably aligned for the data fields of
>>> the control messages.)
>> The way it is normally is make it an array of the maximally aligned
>> type (usually of type long or long long).
> Knowing what "the maximally aligned type" *is* is machine- and/or
> compiler-dependent. (For example, I could easily imagine a 32-bit
> machine on which long and long long could be on any 32-bit boundary but
> double must be on a 64-bit boundary.)
Except that CMSG_* will not be returning a double or float. 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.
> Unless you are counter-proposing to have the CMSG_* interface export a
> type for the purpose, which would at least _suffice_, though I'd still
> prefer to do away with overlaying the structs onto the buffer - or at
> least make it possible for the app author to do so.
What I am saying CMSG_* is sufficient if you specify an aligned buffer
and the mechanism for that is not onerous. I think you are making a
mountain out of molehill.