Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!news From: scs@adam.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: Array question Message-ID: <1991Feb15.194538.4217@athena.mit.edu> Date: 15 Feb 91 19:45:38 GMT References: <7060009@hpfcso.FC.HP.COM> Sender: news@athena.mit.edu (News system) Reply-To: scs@adam.mit.edu Organization: Thermal Technologies, Inc. Lines: 47 In article <7060009@hpfcso.FC.HP.COM> pgt@hpfcso.FC.HP.COM (Paul G. Tobin) writes: >Michael Stefanik wrote: >* One thing to point out is that pointers and arrays are _not_ interchangable >* entities _except_ when you are passing them to functions. > > Michael, can you clarify this a little bit? I thought >pointers and arrays in C _were_ interchangeable... It never ends. This time, at least, the confusion is not over the difference between pointers and arrays, but over the interpretation of the word "interchangeable." Michael Stefanik's statement had to do with the fact that the declarations extern char a[]; and extern char *a; are not interchangeable, which is a frequent misunderstanding and is discussed at length in the comp.lang.c Frequently Asked Questions list. It doesn't appear that Paul Tobin is unclear on this point; I think he is noting that a program which declares char a[10]; and then makes reference, in an expression, to a[3] can be rewritten to make "a" a pointer: char *a = malloc(10); without any change to the array-like reference. (This is the same point I made in a recent article about realloc.) Actually, there is a change: the compiler emits different code; but the source code for the reference stays the same. I trust we don't need to discuss any of this again right now. Steve Summit scs@adam.mit.edu