litwr wrote:
IMHO C for the 65816 should have 2 pointer types: short (2 bytes) and full (3 bytes).
I considered this whilst drafting my previous reply, and I concluded that its not in the spirit of what C is supposed to accomplish.
The whole point of C as high-level language is to be a "portable assembler", that is, it should provide the programmer almost the same power and speed as writing in assembly but, provided that the programmer strictly conforms to the C standard and doesn't rely on any non-standard platform-specific behaviours, any program they write should be inherently portable between architectures. As soon as you start introducing two different sizes of pointer to be used in different contexts, you've broken that paradigm. Instead, the programmer just uses
size_t which must, by definition, be large enough to contain the full address space, so in our case at least 24-bit. If the compiler is able to optimise down to 16-bit in certain circumstances that is fine and permissiable, but that is an architecture specific detail that should not be visible to the programmer when they are programming in C.
Obviously I am aware that many programs are not actually portable between platforms/architectures, but that is down to either the libraries they must hook into for that platform (which do not exist or are different on other platforms), or the programmer intentionally choosing to rely on implementation-specific behaviour that is not sanctioned by the C standard.
litwr wrote:
How can I point a value in memory above 64 KB using a 2 byte pointer?
As per above, if I were implementing a C compiler for the
65816 I would make
size_t a 32-bit value so that it can fit the full address, but also be more compatible with other platforms and existing C programmers' expectations, and then have the uppermost 8 bits discarded when converting to a data access. However, understanding that 32-bit maths is slower I would optimise down to 16-bit "internal" pointers whenever possible. Infact, this is something that actually occured in the world of the early IBM/DOS PC: you had different "memory models" depending on how much memory your program needed to access, the tradeoff being that giving you access to more space used larger pointers that took longer to process. For details on this Microsoft's Raymond Chen wrote an interesting
blog post on the subject, headaches and legacy of these memory models. One of the key things that these memory models did was redefine
size_t in a non-portable manner - it wasn't always even necessarily the same throghout the program - in order to achieve better performance.
litwr wrote:
So if the 65816 still misses this support it is rather sad.
I agree it is sad that no such thing exists for the
65816, but only because I would enjoy the novelty. I believe the reason it doesn't exist is because it is not practical.
_________________
Want to design a PCB for your project? I strongly recommend
KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of
Retro Computing and
Arduino components you might find useful.