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

> 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.  Since the accesses implicit in
calls such as bind() are outside the scope of the abstract C machine, I
don't think there are any nasal demons there.  (Library routines like
getnameinfo, on the other hand, probably cannot be implemented without
either breaking the aliasing rules or assuming implementation-specific
things about how the structs are laid out in array-of-character terms.
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.)

> The idea in C is that when you first access fresh memory, that
> imprints it with a type.  You're then supposed to use only the same
> type to access it again later, until you free() it.

Well, not necessarily free(); the freeing implicit in a variable of
automatic storage duration going out of scope also counts.  And there
are some exceptions for unions (loosely put, the imprinted type can be
changed by using a different member of the union).  And there's the
"character type" escape....

>> So if TAILQ_HEAD and TAILQ_ENTRY were the same structure, it
>> wouldn't be an issue.  It doesn't quite leap out to me how that
>> would be possible without changing the API a bit.
> I think it can be done by sticking an anonymous union into

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.

> but of course anonymous unions aren't supported until C11.

Or gcc; I think gcc had anonymous unions before C11, didn't it?

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index