Author: David Rasmussen
Date: 01:19:12 01/21/02
Go up one level in this thread
On January 20, 2002 at 18:30:45, Gareth McCaughan wrote: >On January 19, 2002 at 19:47:38, David Rasmussen wrote: > >> I have yet to see an example, besides for the sizeof _feature_, >> where arrays are _not_ the same as constant pointers. > >foo.c: > int a[10]; >foo.h: > extern int * a; > >will get you a linker error (if you're lucky) or >completely broken behaviour (if you're not) when >you try to use |a| from something that includes foo.h . > > typedef int T1[3]; > typedef int * T2; > I said _constant_ pointers. int* is not a constant pointer. You can't declare a contstant pointer in C. You can in C++, but not in C. >Types |T1| and |T2| are not equivalent; for instance, > > T1 x[10]; > T2 y[10]; > >makes |x| and |y| quite different things. > >-- >g Of course. But that was not what I was talking about. Writing int a[10], is of course not the same as declaring a pointer. And as such, a typedef (which is mostly just a typographical thing), wont change that. If you have to compare predefined arrays (which are always of size > 0), you have to compare with pointers pointing to allocated memory (whether on the heap or on the stack), of at least one element. And what I am saying is that in such a case, an array _is_ a constant pointer. If you declare int a[10], a is a constant pointer, that is, a is a pointer, and you can't change it's value. /David
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.