Newsgroups: comp.os.minix
Subject: Re: "(warning) old-fashioned function definition"
References: <5fdf14af.0107011533.be62270@posting.google.com> <l26qh9.69.ln@nnews.ath.cx> <3b40a47c.0@news.syr.edu> <mdfqh9.ca.ln@nnews.ath.cx>
Organization: Syracuse University, Syracuse
From: mcconnel@hydra.syr.edu (Terry R. McConnell)
NNTP-Posting-Host: hydra.syr.edu
Message-ID: <3b40ce6c.0@news.syr.edu>
Date: 2 Jul 2001 15:41:32 -0500
X-Trace: 2 Jul 2001 15:41:32 -0500, hydra.syr.edu
Lines: 40
Path: news.adfa.edu.au!clarion.carno.net.au!news0.optus.net.au!news1.optus.net.au!optus!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.syr.edu!hydra.syr.edu!mcconnel
Xref: news.adfa.edu.au comp.os.minix:37756

In article <mdfqh9.ca.ln@nnews.ath.cx>, Paul <paul@mmail.ath.cx> wrote:
>> >Can someone explain "char (*map)[25]"?
>> >
>> map is a pointer to an array of 25 chars.
>> An array of 25 pointers to chars would be char *map[25].
>
>If "char (*map)[25]" is a pointer to an array of 25 chars, then
>why not just "char map[25]"???
>
>The only advantage I can think of is that "map" is not a constant in the
>that case...
>but it doesn't make sense to have non-constant pointer when you are
>allocating memory at the same time.....if you points "map" somewhere else,
>the allocated memory is not accessable any more..
>something is not right here....fishy.....
>


If you declared char map[25] and passed map to a function expecting a
char (*)[25] you'd get a compiler warning from an ansi compliant compiler. 
The call would work anyway, because array names "decay" into 
pointers to their first elements whenever used in an expression (in particular,
in a function call argument list.) 

If the function really needs a pointer to exactly 25 chars then 
declaring the function as needing such helps to document this fact and makes
the code easier to maintain. It may well be that the calling code needs to
cycle map among various 25 element arrays. In this case you would need
to declare it as a pointer since, as you correctly pointed out, you cannot
assign to an array name. 

BTW, the declaration char (*map)[25] does not allocate memory for 25 chars. It
only allocates memory to store the pointer. The declaration char map[25] does
allocate memory for 25 chars.

-- 
************************************************************************
Terry R. McConnell   Mathematics/304B Carnegie/Syracuse, N.Y. 13244-1150
trmcconn@syr.edu     http://barnyard.syr.edu/~tmc    Question Authority?
************************************************************************
