Pointer arithmetic and comparisons.

Earl Fogel fogel at dvinci.usask.ca
Sat Dec 16 02:38:06 AEST 1989


daveh at marob.masa.com (Dave Hammond) writes:
>Machine/OS: 286-compatible/MSDOS
>Compiler: Turbo-C 1.5
>
>The problem occurs when the address resulting from &buffer[len] exceeds
>65535.  For example, if &buffer[0] is 65535 and len is 100, &buffer[len]
>becomes 99, making `while (p < e)' immediately false.
>
>I was under the impression that (for n > 0) buffer[n] should not yield
>an address lower than buffer[0].  Is the pointer comparison I am doing
>non-portable, or otherwise ill-advised ?
>

The problem, I believe, is in the Memory Model you are using in
Turbo C.  If your data does not all fit into one 65535 byte segment,
then you have to declare pointers to be 'huge' for them to properly
address your buffer.



More information about the Comp.lang.c mailing list