home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.std.c
- Subject: C arrays.
- Message-ID: <16052@goanna.cs.rmit.oz.au>
- Date: 24 Nov 92 01:49:55 GMT
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 66
-
- I have been having an argument with someone who thinks I am a dolt about C.
- This may be so. I would like to correct my understanding.
-
- Is there anything which Pascal arrays _can_ do that C arrays can _not_
- do, other than the following three compile-time issues:
-
- (a) Pascal arrays may be _declared_ as having an enumeration type
- for a particular index. In both languages enumerations may be
- _used_, but only Pascal can require it. Under the influence
- of Ada I count 'char' as an enumeration type.
-
- (b) Pascal arrays may have lower bounds other than 0.
-
- (c) Pascal arrays may be assigned and passed by value without
- first being wrapped in a "struct". (That is, the _effect_ of
- assigning arrays and passing them by value may be concisely
- obtained in standard C, but not _directly_.)
-
- In particular, my understanding is that when it comes to checking
- array subscripts, Pascal and C are identical save in one respect.
- They are identical in that both standards _permit_ but in no wise
- _require_ subscript checking (compile-time or run-time). The one
- difference is that given
- SomeType a[N]; a: array [1..N] of SomeType;
- both languages permit
- x = a[i]; x := a[i+1];
- a[i] := x; a[i+1] := x;
- for precisely the same values of i, but C additionally permits
- the formation of the pointer
- &a[i] for 0 <= i <= N
- while Pascal implicitly permits this only for 0 <= i < N.
-
- In this case we have something that C arrays _can_ do and Pascal
- arrays can _not_. There are other many other things that can be
- done with C arrays but not Pascal arrays.
-
- The person who thinks I am a dolt about C claims that C is a more "bare
- bones" language than Pascal, and explicitly cites arrays as something that
- Pascal supports and C doesn't. Apart from the three points (a), (b), and
- (c) above, I cannot at the moment recall any single construct which Pascal
- arrays support and C arrays do not. (Conformant array parameters do not
- count: they are optional in the ISO standard and absent from the ANSI one.)
-
- I am posting in this group because the interesting question is what the
- C _standard_ says about arrays, not what any particular implementation may
- do.
-
- As a further point which does not deserve a separate posting,
- my understanding is that in the context
-
- #include <math.h>
-
- ... float x, y;
- ... x = sqrt(y);
-
- a C processor may use a single-precision version of sqrt(). This is
- certainly so for the arithmetic operators like +; is it also so for
- the math functions? I have a copy of the draft specification of the
- math functions for Ada; that includes fairly tight bounds on precision.
- I am informed that the C standard does _not_ contain tight bounds on the
- precision of the math functions, so the answer to my question may be
- "yes, because the standard doesn't specify sqrt() tightly enough to tell
- the difference."
-
- (For what it's worth, I put in another request for a copy of the standard
- about two months ago.)
-