Path: utzoo!attcan!uunet!samsung!olivea!orc!inews!cmdnfs!bhoughto From: bhoughto@cmdnfs.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Finding Available Length Of Strings... Message-ID: <931@inews.intel.com> Date: 12 Nov 90 16:59:49 GMT References: <16752@hydra.gatech.EDU> <14411@smoke.brl.mil> <921@inews.intel.com> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 40 In article <921@inews.intel.com> bhoughto@cmdnfs.intel.com (Blair P. Houghton) writes: >"pointers to arrays containing chars"? > typedef char A[SIZE]; > A *foo; > >Note also that, since it is a pointer >to an array rather than a pointer to char, you have to get >the chars through `*foo[i]' or `**foo' rather than `*foo' >or `foo[i]'. I'm sorry, this is wrong. The `[]' have a higher precedence than the `*', so it would have to be `(*foo)[]' for the subscripted version, if `foo' were a pointer to a pointer. In order to use `foo' (as anything other than NULL) you have to provide an array of the proper type, properly allocated, and then assign the "address" of that array to `foo'. But, in the act of assigning that address, you turn the array into the pointer to its first element. There is in fact no way to get the address of an array without actually getting the address of the first element. This still does not make the two of them compatible types[*]. However, it means that `**foo' is not correct. `*foo' is the proper pointer dereference to get `array[0]', `foo[i]' is the proper subscripted version, even though `foo' is a proper pointer-to-array. [*] The assignment `foo = &bar' is right, the assignment `foo = bar' is incorrect (gcc -ansi just produces a warning, but, if you believe in the Pointer Fairy (as you and Doug know I do :-), you believe that all pointers are the same, anyway, so `foo = bar' works even though it's hubris; but don't trust it). --Blair "The PF still owes me a quarter. She's probably just waiting for those pointer-subtraction semantics I promised I'd post... :-/"