tech-userlevel archive

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

Re: why cast to char* through void*

On Fri, Jul 03, 2009 at 05:52:01PM -0400, Greg A. Woods wrote:
> At Fri, 3 Jul 2009 16:04:39 -0400 (EDT), der Mouse 
> <mouse%Rodents-Montreal.ORG@localhost> wrote:
> Subject: Re: why cast to char* through void*
> > 
> > Thor is right from what I might characterize as C's original target: an
> > implementation languages for things, such as the low levels of
> > operating systems, where type-unsafe operations such as bytewise access
> > to structures, or treating pointers as the bit patterns that make them
> > up, are fundamentally necessary.
> Well, yes, but that's where I'm trying to say it is appropriate to use
> /*LINTED*/ comments.  These kinds of pointer aliasing tricks are indeed
> sometimes necessary, but it is not appropriate to have lint (or the
> compiler) always ignore the fact that the programmer is doing something
> behind the compiler's back, [...]

My position is simple: in this particular case it is best to have lint
and the compiler enforce the same pointer aliasing rules (which happen
to be, actually, the strictest realistic interpretation of the rules
actually encoded in the standard: anything *except* char * may be
assumed to alias anything else).

If, in this case, the compiler and lint enforce different rules, it's
just going to cause people to do more dangerous things to try to achieve
impedance matching.  I tend to agree with Christos that /* LINTED */ is
one such because, more often than not, I see it used to shut up lint
in cases which really _are_ wrong, so I do not want to see it in the
NetBSD sources, much as I don't want to see casts to (void *).


Home | Main Index | Thread Index | Old Index