home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1833 < prev    next >
Encoding:
Text File  |  1992-12-18  |  5.5 KB  |  143 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Dec17.213129.7779@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec4.093044.16823@jyu.fi> <1992Dec07.225634.19943@microsoft.com> <1992Dec8.143504.5590@jyu.fi>
  10. Date: Thu, 17 Dec 1992 21:31:29 GMT
  11. Lines: 130
  12.  
  13. In article <1992Dec8.143504.5590@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
  14. >In article <1992Dec07.225634.19943@microsoft.com> jimad@microsoft.com (Jim Adcock) writes:
  15. >>
  16. >>Agreed, and in general those changes have been practical and well motivated.
  17. >>What you suggest is neither.  On the contrary, you ask to legalize your
  18. >>favorite hacks.
  19. >
  20. >No, it's you who are crying for hacks:  programs that happen to work
  21. >in a certain way because of the peculiarities of a certain compiler.
  22. >Now you think it has been OK to break many "strictly conforming" programs!
  23.  
  24.     BOTH hacks! OK?
  25.  
  26.     Jims is a 'hack' because it is machine and compiler and even
  27. memory model dependant. Fine. C was designed to handle that. It was
  28. designed for controlling hardware every bit as much, and maybe moreso,
  29. than general programming.
  30.  
  31.     Markku's is a hack because linear address machines,
  32. for which pointer comparison makes the most sense, are just
  33. one possible architecture. And one which went out of date
  34. many years ago I thought. Aren't von Neumann machines considered
  35. archaic? Isnt the segmented architecture (I mean real
  36. segments like the 386 not 8086 bank switching) just an extension
  37. of the Harvard architecture? Aren't BOTH of these 
  38. going to become obsolete with the advent of 
  39. distributed persistent object stores?
  40.  
  41. >
  42. >You have been pleaded a dozen times to give an example.
  43. >Why don't you present one, so we can get this discussion on more
  44. >rational grounds!
  45.  
  46.     I presented one.. twice. If you want more,
  47. look at almost every C program ever written
  48. for the PC. Many use mixed pointer types. 
  49.  
  50.     Here's an easy example from Microsoft's older 
  51. libraries:
  52.  
  53.     memcpy(void*d, void*s, int n);
  54.  
  55. Here d and s are only 16 bits. So they had better both
  56. reside in the Data Segment, or all hell breaks loose.
  57. This version of memcpy assumes this is the case.
  58. If you want 20 bit addresses, use
  59.  
  60.     far_memcpy(void _far * d, void _far * s, int n);
  61.  
  62. (Or something similar, Borland's libraries never had this problem).
  63.  
  64. While this isn't an example where total ordering matters,
  65. perhaps you might begin to see how bad things are for
  66. 8086 programmers. And perhaps you can understand that
  67. there are sure to be dependencies on pointers being
  68. ordered the 8086 way in 8086 code. On the 8086,
  69. they can be used just like 16 bit integers, and often are.
  70.  
  71.     A function 
  72.  
  73.     ptrcmp(void*,void*);
  74.  
  75. wouldnt work if the ptrs were 16 bits anyhow. The < version
  76. is bound to use that implementation for consistency.
  77. The true library function must be
  78.  
  79.     ptrcmp(void _far *, void _far *);
  80.  
  81. >>
  82. >>Wrongo.  Again you confuse language and implementation.  On the contrary, 
  83. >>I've written an internal implementation of C++ that does have the means to 
  84. >>automatically track down and modify all pointers to an object.  There
  85. >>are other systems that do this kind of thing too.  Such as early versions of
  86. >>Windows.
  87. >
  88. >Maybe, but such a system must be terribly expensive in memory and
  89. >processor time;  and your main motivation seemed to be to save
  90. >a couple of processor cycles.
  91.  
  92.     Windows was expensive on processor time in order
  93. to conserve memory. It had to run on the 8086, in 640K, and did.
  94. Pointers in Windows (real version) were not allowed, except for transient
  95. periods. It had automatic compaction, including chasing the stack
  96. for stack frames. It dumped read-only segments automatically,
  97. and reloaded them just as automatically when required.
  98.  
  99.     And the guys that wrote it are now the richest men in 
  100. the US because of it. And more people us it than any other
  101. GUI. Dont laugh, Microsoft has NT running on MIPS, Unix beware!
  102.  
  103. >
  104. >is not portable.  Some people indeed want to write portable software,
  105. >and not only for a 1970s state-of-the-art Deci (one tenth) Operating System.
  106.  
  107.     Hey, others want to write for Unix, which is not
  108. much of an operating system compared to say OS/2 or NeXT either :-).
  109.  
  110. >
  111. >I already explained that the issue was not to program in terms of
  112. >memory addresses!
  113. >
  114.     How then does one write an operating system, device
  115. drivers, or any other code that MUST assume pointers are
  116. memory addresses?
  117.  
  118.     The problem is that pointers should be useful BOTH
  119. as memory addresses, and also as 'object accessors'.
  120. Really, operations like p++ should not be legal on
  121. pointers, but we're stuck with them.
  122.  
  123.     The real problem is that pointers have a meaning
  124. defined by prior C definitions, and so much code
  125. depends on those definition that its not possible
  126. to change them.
  127.  
  128.     Now if we could write proper object accessors
  129. efficiently and conveniently, we wouldn't need to use
  130. pointers .. except for machine level access.
  131. So perhaps we need operator.() and/or something else
  132. to be able to do this, because at the moment we
  133. cant emulate pointer behaviour in classes.
  134.  
  135.     Would it be more profitable to consider
  136. why this is, and what we can do about it?
  137.  
  138. -- 
  139. ;----------------------------------------------------------------------
  140.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  141.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  142. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  143.