tech-userlevel archive

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

Re: why cast to char* through void*

At Sat, 4 Jul 2009 17:09:42 +0000, David Holland 
<> wrote:
Subject: Re: why cast to char* through void*
> On Fri, Jul 03, 2009 at 05:52:01PM -0400, Greg A. Woods wrote:
>  > 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, 
> No amount of LINTED will prevent demons from flying out of your nose
> if you do something that isn't defined. That's the concern.

Indeed -- but the "undefined" behaviour you speak of, I think, is the
very strict and narrow meaning given by the C Standard.

The purpose of using LINTED to mark section of code that exploits a
"strictly undefined" behaviour (i.e. and not changing that code to avoid
the problem in the first place) is to say that we know what's happening
here and we're pretty sure the implementation we're using, and/or the
environments we've prepared the code to be used in, will not cause any
demons to fly out of anywhere, but if someone else moves this code to
another platform they should carefully check the marked code to be sure
it doesn't need changing to avoid demons in the new environment.

Indeed that's also probably the real reason why lint and gcc are giving
different warnings here -- lint is sticking closer to the "strictly
undefined" side of the fence, and gcc (being the actual implementation)
is saying that the cast through (char*) is OK because it will do what's
expected here (i.e. this implementation has a well defined behaviour).

Lint(1) should probably have an option to ignore LINTED comments though
to aid those preparing a port to another environment.  Perhaps '-p'
should do that by default.

Dumbing down lint, and/or making it specific to only one dialect and/or
implementation, would be a bad thing.

                                                Greg A. Woods
                                                Planix, Inc.

<>       +1 416 218-0099

Attachment: pgpukr0p04Dig.pgp
Description: PGP signature

Home | Main Index | Thread Index | Old Index