Incrementing after a cast

.csnet .csnet
Thu Dec 25 08:17:50 AEST 1986


Casts are conversions? Oh? You'd never know it looking at the code that
out of my C compilers ... including Harbison's!  He just regards away.

The fact that there are machines which would like to have C compilers on 
which ((sometype *)p)++ doesn't work as a "regard as" only means that 
these machines aren't compatible with a lot of people's notion of C's model 
of computation. There's a whole lot more machines on which ((sometype *)p)++ 
makes perfect legal, technical, and useful sense and these happen to be C 
machines. Why lots of people with ordinary machines can't do something 
useful, intuitive, and natural because some solder-crazed EE somewhere might,
just might mind you, someday do something unnatural to his memory system is 
beyond me.  

If you insist on being strict, here's a definition of ((sometype *)p)++ 
which will work on any machine:

	"Think of the bits refered to as p as a (sometype *).
	 If don't have enough bits or you have too many bits 
	 do something reasonable.  Now increment the (sometype *)
	 you're thinking of.  Now put the results back into p.  
	 If you	 don't have enough bits or you have too many bits, 
	 do something reasonable."

And no noise please about doing something reasonable because 1) we do it 
all the time with numbers so why not with pointers too, 2) it's probably 
what you want any way, and 3) it'll never have to be done on machines that 
are reasonable to begin with. (By the way there is no reason why ((x+1) = 10)
shouldn't work too.)

I forsee a day when there are two kinds of C compilers: standard ones and 
useful ones ... just like Pascal and Fortran.  Are we making progress yet?



More information about the Comp.lang.c mailing list