rfg@paris.ics.uci.edu (Ronald Guilmette) (02/13/90)
/* gcc 1.36 question 891215_02
Should the following code generate either errors or warnings when compiled
with an ANSI conformant C compiler?
The question really is: "What is the type of a?" Is the type of `a'
simply `int *' or is it `int * const'?
*/
int *p;
void function (int a[])
{
a = p;
}
rex@aussie.UUCP (Rex Jaeschke) (02/14/90)
> Ronald Guilmette writes: > The question really is: "What is the type of a?" Is the type of `a' > simply `int *' or is it `int * const'? > > */ > > int *p; > > void function (int a[]) > { > a = p; > } In the scope of a definition (or an extern declaration) of an array, the array name IS a const pointer. Not so though when used as a formal parameter. At that stage arrays and pointers are synonymous. In fact ANSI C requires that arguments be passed by value and that a private MODIFIABLE copy be made available to the called function. As such, a++ is valid inside function above. If, however, the formal parmeter were declared as (int * const a) then a would be a const pointer. (I don't see how to declare as such using array notation though since const int a[] is NOT the same thing.) Rex ---------------------------------------------------------------------------- Rex Jaeschke | Journal of C Language Translation | C Users Journal (703) 860-0091 | 2051 Swans Neck Way | DEC PROFESSIONAL uunet!aussie!rex | Reston, Virginia 22091, USA | Programmers Journal ---------------------------------------------------------------------------- Convener of the Numerical C Extensions Group (NCEG) ----------------------------------------------------------------------------