|
From: Kohn E. D. <em...@cs...> - 2002-06-14 14:50:49
|
On Thu, 13 Jun 2002, Aliberti Emanuele wrote: > >The ability to cast arrays to pointers without using & is a compiler > >trick. A dangerous trick IMHO. > > It's not casting. Arrays ARE pointers in C. Square brackets are a language construct to avoid explicit pointer computations. Arrays are *not* pointers in C. However, with few exceptions (such as passing them as arguments to sizeof()), an array is similar to a pointer to its first element. ... int arr[10]; int* pi = arr; ... The expression &arr will yield something of type `pointer to array of 10 integers'. While both arr and &arr yield the same value when printed, these pointers are *different types*, in that, for example, arr + 1 will yield the address of the second element in the array (i.e. &arr[1]), while &arr + 1 will yield the address of one element past the end of the array (i.e. &arr[10]). There are of course other differences, too. Obviously pointers to integers are not compatible with pointers to arrays. Therefore the following code will not compile without an error or at least a warning from the compiler: ... int arr[10]; int* pi = &arr; ... To designate a pointer to array you need to use the following syntax: int (*parr)[10] = &arr; I hope that this clarifies the issues. Emil > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink > > _______________________________________________ > reactos-kernel mailing list > rea...@li... > https://lists.sourceforge.net/lists/listinfo/reactos-kernel > |