X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: array size inside of a function Date: 4 Mar 2004 13:57:20 GMT Organization: Aachen University of Technology (RWTH) Lines: 29 Message-ID: References: NNTP-Posting-Host: ac3b07.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 1078408640 16619 137.226.33.205 (4 Mar 2004 13:57:20 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 4 Mar 2004 13:57:20 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Andrey wrote: > > sizeof(char **) == address size = 4 on 32bit machines. > > > so in main(), array name is not a pointer? Right. It will "decay" into a pointer if you use it as one, but it "is" not a pointer. This is a very common misunderstanding among new C programmers, and unfortunately one that is being stated as fact by many careless C book authors. Passing an array as an argument to some function is one of the usages that counts as "using it as a pointer". The only cases that don't count as such, actually, are use of the 'sizeof' or '&' operators on the name of the array. > and there no way free from passing size? Essentially: no. It's thus usually a good plan to join the pointer and the length into a struct: typedef struct array_of_foo { foo *pointer; size_t length; } array_of_foo; -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.