tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: in which we present an ugly hack to make sys/queue.h CIRCLEQ work



On Sat, Nov 23, 2013 at 12:59:04AM -0500, Mouse wrote:
 > > Note that the bog-standard (struct sockaddr *) cast that one needs
 > > and conventionally uses to call bind(2), connect(2), accept(2), and
 > > similar is, strictly speaking, illegal.
 > 
 > I don't think so.  The aliasing rules don't say anything about the
 > types used when passing around pointers to an object, only about the
 > types used when actually accessing it.

Indeed. But it *is* accessed via both types. That the kernel copies it
before accessing it doesn't (AIUI) matter. The compiler is not in a
position to see both ends of this at once; but that's why I said
"strictly speaking".

 > To be type-correct, the various structs sockaddr_* really need to be a
 > single discriminated union...and I'm not sure sockaddr_un can ever be
 > done type-correctly; I'd have to think about it more.)

Why not? Worst case is that your union is size PATH_MAX plus a bit.

 > (some further notes skipped, no disagreement)
 >
 > > I think it can be done by sticking an anonymous union into
 > > TAILQ_HEAD,
 > 
 > I'm not sure, since storing through one union member and fetching
 > through another brings back issues.  I'd need to see details to do more
 > than take guesses, though, of course.

I believe that was explicitly legalized in C99 TC3.

 > > but of course anonymous unions aren't supported until C11.
 > 
 > Or gcc; I think gcc had anonymous unions before C11, didn't it?

It's had them for ages and ages, yeah.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index