User: Password:
|
|
Subscribe / Log in / New account

would using casts fix the problem?

would using casts fix the problem?

Posted Apr 16, 2008 21:29 UTC (Wed) by MathFox (guest, #6104)
In reply to: would using casts fix the problem? by jengelh
Parent article: GCC and pointer overflows

I guess that you missed the point completely. aend-a (no casts needed) should give 10 on any platform. The bit pattern in a pointer is implementation defined and that particular platform had (64-bits IIRC) word-based addresses in a 48 bit address space. The low 48 bits of a character pointer were the address of the word containing the character; the high bits addressed the byte in the word.

Standard conforming programs don't rely on pointer layout.


(Log in to post comments)

would using casts fix the problem?

Posted Apr 17, 2008 18:55 UTC (Thu) by hummassa (subscriber, #307) [Link]

yes,
  aend - a
(without cast) _is_ 10 in any platform, but
  (int)aend - (int)a
is _undefined_ behaviour, because the bit pattern when converting from 
pointer to int is implementation-defined.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds