| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
| From: | Michael Beck <beck AT ipd DOT info DOT uni-karlsruhe DOT de> |
| 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: | <c2489p$oce$1@news.rz.uni-karlsruhe.de> |
| References: | <baec0bf0 DOT 0403022220 DOT 3534cf24 AT posting DOT google DOT com> |
| NNTP-Posting-Host: | i44pc33.info.uni-karlsruhe.de |
| Mime-Version: | 1.0 |
| 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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |