NetBSD-Bugs archive

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

Re: toolchain/43234: lint warns about perfectly good casts



The following reply was made to PR toolchain/43234; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: toolchain/43234: lint warns about perfectly good casts
Date: Thu, 6 May 2010 08:22:38 +0000

 On Tue, May 04, 2010 at 02:10:07PM +0000, Wolfgang Solfrank wrote:
  >  > foo.c(12): warning: pointer casts may be troublesome [247]
  >  
  >  Well, actually lint is perfectly correct in pointing out possible
  >  trouble here.
  >  
  >  I once worked on a 16 bit machine, where most addresses are
  >  16 bit and point to 16 bit values, i.e., the machine has
  >  65536 16 bit words or 128 kB of memory.  In contrast to that,
  >  byte pointers are also 16 bits, but address bytes, i.e. the
  >  machine can only address the low 64 kB using character pointers.
  >  
  >  Casting an int pointer to a character pointer shifts the 16 bits
  >  one bit to the left, loosing the high bit (which poses trouble
  >  if the original value was in the upper 64 kB.)  Of course the
  >  opposite cast shifts to the right, but you can't get the lost
  >  bit back.
 
 Ouch. That isn't compatible with the C standard though. I don't think
 lint should be worrying about such platforms... or at least not until
 we find one we decide we want to port to, and when/if we do that lint
 needs to be very specific about what it thinks might go wrong.
 
  >  I've got no idea, why lint doesn't warn if you add the extra
  >  cast through a void pointer.
 
 Because it does purely local checks, i.e., it's dumb.
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index