R
Richard Heathfield
Morris said:Richard said:char *p = (char *)10000; is legal C, but C offers absolutely
no guarantees that the address you've forced p to point to is
a good place for storing data. This is the kind of trick that
it is best to avoid. For one thing, it's considerably less
portable than Brazil. For another thing, even if it's legal to
write to that space on your system (and it probably isn't, on
modern systems), where do you draw the line? p[100]? p[1000]?
(On the other hand, so-called "badly-behaved" MS-DOS programs
used to do this sort of thing all the time - for an
excellent-at-the-time reason which has become more or less
irrelevant nowadays.)
It's not unusual to see this kind of code used in embedded
systems for which I/O and/or control spaces have been memory
mapped. I agree that it's not portable; but have found it
extremely useful within that limited context.
Oops. Sorry, yes, I'm afraid I was thinking of desktop systems and up. In
the embedded world, hackery of this kind is indeed still invaluable.
Indeed, there are embedded systems nowadays which are far more powerful
than MS-DOS boxes ever were, and perhaps MS-DOS should be thought of as an
embedded system with delusions of grandeur. (I should add that I have a lot
of time for MS-DOS; I regard it with considerable fondness, and indeed
still program for it occasionally.)