On Sun, Jun 04, 2006 at 10:05:22AM -0400, Peter Jay Salzman wrote:
> I gave good reasons *why* passing the pointers should always work. I think
> Micah really got at the heart of the matter:
>
>
> Micah said:
> Pointers to incompatible types are not guaranteed to be represented the
> same way, even though in practice they are. /All/ pointer types must be
> convertible to and from a pointer to any character type, and used as
> such, so this makes it all the more likely that they will be represented
> the same.
>
> Irregardless, the Standard does /require/ that a warning be given when
> you try to do this.
>
>
> I think the main point is the lack of guarantee that they're represented
> the same way. Here's what I think he means.
>
> I *think* what Micah is saying here is that even though a char and signed
> char types have the same width (1 byte) and are implemented the same way in
> practise, there's no guarantee that they *are* implemented the same way.
Actually, no: char and signed char /must/ be represented the same way,
if char is signed.
> For example, a perverse compiler writer may put a byte of dead storage (for
> whatever reason) in between contiguous elements of a char array and 2 bytes
> of dead storage in between contiguous elements of a signed char array.
Well, no, it couldn't. At the very least, you must be able to convert a
pointer to /anything/ to a pointer to character type, and be able to
inspect the byte values in that way.
I was actually talking about the fact that the /pointer/ types don't
have to be represented the same way. A compiler could represent signed
char pointers as a value bit-shifted two to the left, whereas a pointer
to char could be a bitwise complement of the same value. Not likely, but
basically, the Standard committee don't want you just passing stuff
around in general without first declaring, "I know what the hell I'm
doing" (via a cast).
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech