home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3063 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  3.1 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.std.c
  4. Subject: C arrays.
  5. Message-ID: <16052@goanna.cs.rmit.oz.au>
  6. Date: 24 Nov 92 01:49:55 GMT
  7. Organization: Comp Sci, RMIT, Melbourne, Australia
  8. Lines: 66
  9.  
  10. I have been having an argument with someone who thinks I am a dolt about C.
  11. This may be so.  I would like to correct my understanding.
  12.  
  13. Is there anything which Pascal arrays _can_ do that C arrays can _not_
  14. do, other than the following three compile-time issues:
  15.  
  16.     (a) Pascal arrays may be _declared_ as having an enumeration type
  17.     for a particular index.  In both languages enumerations may be
  18.     _used_, but only Pascal can require it.  Under the influence
  19.     of Ada I count 'char' as an enumeration type.
  20.  
  21.     (b) Pascal arrays may have lower bounds other than 0.
  22.  
  23.     (c) Pascal arrays may be assigned and passed by value without
  24.     first being wrapped in a "struct".  (That is, the _effect_ of
  25.     assigning arrays and passing them by value may be concisely
  26.     obtained in standard C, but not _directly_.)
  27.  
  28. In particular, my understanding is that when it comes to checking
  29. array subscripts, Pascal and C are identical save in one respect.
  30. They are identical in that both standards _permit_ but in no wise
  31. _require_ subscript checking (compile-time or run-time).  The one
  32. difference is that given
  33.     SomeType a[N];            a: array [1..N] of SomeType;
  34. both languages permit
  35.     x = a[i];            x := a[i+1];
  36.     a[i] := x;            a[i+1] := x;
  37. for precisely the same values of i, but C additionally permits
  38. the formation of the pointer
  39.     &a[i]    for 0 <= i <= N
  40. while Pascal implicitly permits this only for 0 <= i < N.
  41.  
  42. In this case we have something that C arrays _can_ do and Pascal
  43. arrays can _not_.  There are other many other things that can be
  44. done with C arrays but not Pascal arrays.
  45.  
  46. The person who thinks I am a dolt about C claims that C is a more "bare
  47. bones" language than Pascal, and explicitly cites arrays as something that
  48. Pascal supports and C doesn't.  Apart from the three points (a), (b), and
  49. (c) above, I cannot at the moment recall any single construct which Pascal
  50. arrays support and C arrays do not.  (Conformant array parameters do not
  51. count:  they are optional in the ISO standard and absent from the ANSI one.)
  52.  
  53. I am posting in this group because the interesting question is what the
  54. C _standard_ says about arrays, not what any particular implementation may
  55. do.
  56.  
  57. As a further point which does not deserve a separate posting,
  58. my understanding is that in the context
  59.  
  60.     #include <math.h>
  61.  
  62.     ... float x, y;
  63.     ... x = sqrt(y);
  64.  
  65. a C processor may use a single-precision version of sqrt().  This is
  66. certainly so for the arithmetic operators like +; is it also so for
  67. the math functions?  I have a copy of the draft specification of the
  68. math functions for Ada; that includes fairly tight bounds on precision.
  69. I am informed that the C standard does _not_ contain tight bounds on the
  70. precision of the math functions, so the answer to my question may be
  71. "yes, because the standard doesn't specify sqrt() tightly enough to tell
  72. the difference."
  73.  
  74. (For what it's worth, I put in another request for a copy of the standard
  75. about two months ago.)
  76.