home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20107 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  1.8 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!tulane!uflorida!usf.edu!figment!woodard
  2. From: woodard@figment.tmc.edu (Chris Woodard)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Moving from Pascal to C, Help please!!!!!!
  5. Message-ID: <1993Jan18.215357.2591@ariel.ec.usf.edu>
  6. Date: 18 Jan 93 21:53:57 GMT
  7. References: <C04E63.863@newcastle.ac.uk> <1993Jan5.162504.1680@leland.Stanford.EDU> <4293@dozo.and.nl>
  8. Sender: news@ariel.ec.usf.edu (News Admin)
  9. Organization: University of South Florida, Department of Computer Science and Engineering
  10. Lines: 37
  11.  
  12.  
  13.  
  14. I beg to differ with you on one point.  Segment addresses are *only* ignored
  15. if you're in a memory model that uses 16-bit pointers.  In others, such as
  16. Large and Huge, all 32 bits are important and the segment address *is* used in
  17. the pointer arithmetic.
  18.  
  19. There  _is_ a good reason for using pointers instead of arrays.  If you had
  20. code such as
  21.  
  22. [ example 1]
  23.  
  24.     register char *p1;
  25.         register char *p2;
  26.  
  27.     while( *p1 ) *p2++ = *p1++;
  28.  
  29. to copy the contents of one "string" to another, the generated code only has
  30. to access a single variable (which can be given "register" class for faster
  31. access).  If, on the other hand, you have code such as
  32.  
  33. [ example 2 ]
  34.  
  35.     char p1[26], p2[26];
  36.     int k = 0;
  37.  
  38.     while( p1[k] ) p2[k] = p1[k++];
  39.  
  40. then (a) your source and destination addresses are in const pointers, (b) you
  41. have to access them using an index variable that requires a MOV instruction
  42. for each invocation of the variable, and (c) you have some implicit address
  43. arithmetic in computing the offset into the array in the first place.
  44.  
  45. Making a fetish out of avoiding address arithmetic is a cop-out for people who
  46. aren't comfortable with pointers ... and they should probably stick to
  47. programming in (ugh) Pascal or (double ugh) COBOL, and let the rest of us
  48. alone.
  49.