Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!mips!bridge2!jarthur!polyslo!rcfische From: rcfische@polyslo.CalPoly.EDU (Raymond C. Fischer) Newsgroups: comp.sys.mac.programmer Subject: Re: More on MPW C 3.0 question Message-ID: <25e46fa6.4e8a@polyslo.CalPoly.EDU> Date: 22 Feb 90 23:03:02 GMT References: <162.25dfe4b3@waikato.ac.nz> <10311@hoptoad.uucp> <1629@sequent.cs.qmw.ac.uk> Reply-To: rcfische@polyslo.CalPoly.EDU (Raymond C. Fischer) Organization: Cal Poly State University -- San Luis Obispo Lines: 36 morten@cs.qmc.ac.uk (Morten Ronseth) writes: >In article <10311@hoptoad.uucp> you write: >>ccc_ldo@waikato.ac.nz writes: >>> main() { >>> Str255 >>> temps, *tempp; >> >>"Str255 *tempp" makes no sense. You can't have a pointer to an array >>in C. The compiler should choke on this, but it doesn't. Instead, >>your declarations should go: [edited] >Please, give me a break. Why can't you have pointers to arrays in C? >I mean, how do you explain `char *argv[]' and `char **argv'? >Surely, you must be familiar with this. Although it is a subtle point, C does NOT have pointers to arrays. When an array is reference by its name, the name evaluates to a pointer to the array's first element. This is a pointer to an element of the array, not the entire array. Thus, the type is 'pointer to element' rather than 'pointer to array'. Common 'features' of this are the facts that C arrays do not have any bounds and a pointer variable can be used just like an array variable. One interesting effect of this is the following code. int i, x[20]; i = 5; i[x] = 0; No, I did not make a mistake. The [] is an operator that is equivalent to *(i+x) and so the order doesn't really matter. DON'T DO THIS however; it is incredibly nasty programming style. Ray Fischer rcfische@polyslo.calpoly.edu