While executing the following code:
char far * buf; buf=FARRAY(char, 0x8FFF0); printf("%p\r\n",buf); buf+=0x100; printf("%p\r\n",buf);
x:08fff0 x:0800f0
It's a known limitation. But since it's documented, it's not a bug. Objects in contiguous mode can be far away, yes, but that doesn't mean they must also be able to be huge, or be allowed to straddle 64K page boundaries. Even the compilers for 16-bit platforms often don't fully support objects straddling 64K boundaries, what did you expect from an 8-bit platform?
Thanks for the answer. Can you point me where is this behaviour documented (which document, chapter in it)? > Even the compilers for 16-bit platforms often don't fully support objects straddling 64K boundaries, what did you expect from an 8-bit platform? I expexted from Keil to outperform those undecent compilers. :-)
By default, pointer operations use 16-bit math. So, the rollover you see is expected. What happens if you change the buf += 0x100; to...
buf+=0x100UL;
Hello! 0x100UL does the trick and now MSB of buf pointer is updated to 0x09. But consider more complicated example: typedef struct a{ char x[0x100]; char y[0x100];} struct_a; .......................... struct_a far * buf; buf=FARRAY(struct_a, 0x8FFF0); printf("%p\r\n",buf); printf("%p\r\n",buf->y); I get it again: x:08fff0 x:0800f0 What can you advice in such a case when structure is crossing 64K boundary? By the way I've already found the note in the "C51 User's guide": The absolute addressed object cannot cross a 64KB segment boundary. For example, you cannot access a long array that has 10 elements and starts at address 0xFFF8. Is that note still valid for the Dallas chips with true 24-bit DPTR's? I suspect yes... :(
typedef struct a{ char x[0x100]; char y[0x100];} struct_a; .......................... struct_a far * buf; buf=FARRAY(struct_a, 0x8FFF0); printf("%p\r\n",buf); printf("%p\r\n",buf->y);
Oh, finally I've found it: http://www.keil.com/support/man/docs/c51/c51_le_far.htm Bottom line: yes, this is not a bug, this is a feature. It is my responsibility to not place objects over the 64K boundaries. Dot.