home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Subject: Re: Peek/Poke in C
- Message-ID: <1992Dec18.193320.20790@klaava.Helsinki.FI>
- Organization: University of Helsinki
- References: <pal.724673747@regent.e-technik.tu-muenchen.de> <BzGIDn.Ho4@news.cso.uiuc.edu> <mcdonald.621@aries.scs.uiuc.edu>
- Date: Fri, 18 Dec 1992 19:33:20 GMT
- Lines: 55
-
- mcdonald@aries.scs.uiuc.edu (J. D. McDonald) writes:
- >AND FOLKS, PLEASE, don't go blathering about "portability". It makes you
- >look silly. If the address of something on you computer is 13556, that's
- >what it is, and you have no choice about using it.
-
- True, if you have to access memory location 13556, then you have to
- access memory location 13556. The question is, do you have to access
- memory location 13556? ;-)
-
- It is my experience that many programmers in the wonderful (or not so
- wonderful) realm of DOS answer this question far too quickly with an
- "Of course!". In practice, what they are after is either utilizing
- some machine specific peculiarity (such as getting a random number by
- reading from the counter updated by the timer interrupt), or
- "efficiency". I put that in quotes, because what they mean by
- efficiency usually means just writing directly to the screen,
- especially in programs where that portion of the program is not a
- bottlneck, like in a program that counts words in files (the program
- will spend several minutes in reading files, then the answer has to be
- poked directly to the screen memory in order to save a millisecond or
- two).
-
- The fact that the services that MS-DOS provides are inadequate, and in
- the old days way too slow (the hardware is fast enough now that e.g.
- using DOS for writing things to the screen is quite fast enough in
- almost all cases), has lead to the DOS Programmer Syndrome. People
- suffering from this disease make the assumption that any program that
- does anything useful has to access the hardware directly and bypass
- the operating system. The earliest sign is usually that they want to
- write their own library for writing things directly to the screen
- memory.
-
- I'm not saying that all cases of accessing the hardware are wrong,
- just that it is way too common a practice, and often not even the best
- answer.
-
- Also, the same syndrome probably affects programmers using other tools
- as well, but it seems to be worst among DOS programmers.
-
- >The answer is "if you can do it at all in C, you cast the address to
- >a pointer of the proper sort and access that pointer ...
-
- The cast might not work, but the implementation might still provide a
- way to do it (e.g. via a library routine, or an extension to the
- language, such as a new operator), so I think that the correct answer
- is "please check your friendly manual; if that doesn't work, try using
- a cast".
-
- >But remember, you purists out there, this likely **IS** kernal code.
-
- Only as far as any program running under DOS is kernal code.
-
- --
- Lars.Wirzenius@helsinki.fi (finger wirzeniu@klaava.helsinki.fi)
- MS-DOS, you can't live with it, you can live without it.
-