X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Michael Beck Newsgroups: comp.os.msdos.djgpp Subject: Re: array size inside of a function Date: Wed, 03 Mar 2004 10:25:12 +0100 Organization: University of Karlsruhe, Germany Lines: 30 Message-ID: References: NNTP-Posting-Host: i44pc33.info.uni-karlsruhe.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.rz.uni-karlsruhe.de 1078305913 24974 172.22.85.161 X-Complaints-To: usenet AT rz DOT uni-karlsruhe DOT de User-Agent: KNode/0.7.1 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Andrey wrote: > char *array[size]; > > function(char *array[]) > { > > // array[0] returns string #0, but sizeof(array) returns 4 > // Why returns 4? > // Is there any way to get size here? > } [..] This is the way C is specified. function(char *array[]) is simply a "more understandable" version of function(char **array), and sizeof(char **) == address size = 4 on 32bit machines. They simpliest way to get around this is the following: function(char *array[], size_t num_elements); main() { function(a, sizeof(a)/sizeof(a[0])); } BTW: Most languages that support this construction (Modula-2 for instance) implicit add this parameter :-) best regards, -- Michael Beck beck AT ipd DOT info DOT uni-karlsruhe DOT de