home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / modula2 / 1582 < prev    next >
Encoding:
Text File  |  1992-12-16  |  3.4 KB  |  73 lines

  1. Newsgroups: comp.lang.modula2
  2. Path: sparky!uunet!munnari.oz.au!metro!seagoon.newcastle.edu.au!wombat.newcastle.edu.au!eepjm
  3. From: eepjm@wombat.newcastle.edu.au (Peter Moylan)
  4. Subject: Re: Generic stack implementation
  5. Message-ID: <1992Dec17.114912.1@wombat.newcastle.edu.au>
  6. Lines: 61
  7. Sender: news@seagoon.newcastle.edu.au
  8. Organization: University of Newcastle, AUSTRALIA
  9. References: <9212091316.AA14856@elg> <911288c.32.724187845@ace.acadiau.ca> <1992Dec15.150410.21677@informatik.uni-ulm.de>
  10. Date: Thu, 17 Dec 1992 00:49:12 GMT
  11.  
  12. In article <1992Dec15.150410.21677@informatik.uni-ulm.de>, borchert@titania.mathematik.uni-ulm.de (Andreas Borchert) writes:
  13. > In article <911288c.32.724187845@ace.acadiau.ca>, 911288c@ace.acadiau.ca (HON (EDWIN) KIN CHUNG) writes:
  14. >> In article <9212091316.AA14856@elg> ob@IFI.UIB.NO (Ole-Bjorn Tuftedal) writes:
  15. >> >         INC(location, TSIZE(WORD));
  16. >>         ^^^^^^
  17. >>         parameter not correct type ??
  18. >> 
  19. >>     Is this some problem ...???
  20. >>     I am using TopSpeed Modular-2.
  21. > Obviously, TopSpeed Modula-2 violates PIM3 which states in the report
  22. > (system dependent facilities) that ADDRESS "is compatible with all pointer
  23. > types, and also with the type CARDINAL. Therefore, all operators for
  24. > integer arithmetic apply to operands of this type. Hence, the type
  25. > ADDRESS can be used to perform address computations and to export the
  26. > results as pointers."
  27.  
  28. On the other hand, PIM3 is rather vague on what the result of the
  29. computation will be.
  30.  
  31. Suppose a word holds four bytes on your machine.  Does the operation
  32.     INC (location, TSIZE(WORD))
  33. increment the pointer by four bytes, or by four words?  The answer
  34. probably depends on whether your machine has byte-addressable memory
  35. or word-addressable memory.  Some compiler writers get around this
  36. problem by considering ADDRESS to be equivalent to POINTER TO BYTE
  37. - but this violates the PIM3 rules, which say that an ADDRESS works
  38. like a POINTER TO WORD.
  39.  
  40. Suppose further that a CARDINAL fits into one word, and that a
  41. pointer needs two words.  (And that the very useful LONGCARD is
  42. not implemented, since PIM3 does not require it.)  What precisely is
  43. meant by the statement "ADDRESS is compatible with CARDINAL" in this
  44. case?
  45.  
  46. If pointer arithmetic is legal, can you add two pointers together?
  47. Even most assemblers, for a huge variety of machines, consider this
  48. to be illegal, for some very good reasons.
  49.  
  50. It looks to me as if the PIM3 statements about address arithmetic
  51. were made before Wirth had started thinking about portability
  52. issues.  I'm convinced that this is a design error, which would
  53. probably have been fixed if PIM5 had ever appeared.
  54.  
  55. > Despite of some odd architectures (8086 and upward belong to these class)
  56. > address arithmetic is quite portable. As an example, C uses address
  57. > arithmetic extensively and it runs on nearly any platform.
  58.  
  59. Have you ever tried to port a large C program from one platform to
  60. another?  Fixing up the address arithmetic in a supposedly portable
  61. C program can be a major headache.
  62.  
  63. The design of C presupposes a linear address space.  As soon as you
  64. try to use C with a segmented architecture, you find yourself having
  65. to write C in a style which is not quite standard C.  Even so, pointer
  66. arithmetic in C is actually a bit more portable than the PIM3 pointer
  67. arithmetic, because of the C rule that pointer arithmetic includes an
  68. invisible adjustment for the size of the objects being pointed to.
  69.  
  70. -- 
  71. Peter Moylan                      eepjm@wombat.newcastle.edu.au
  72.