A simple typing question.

Rex Jaeschke rex at aussie.UUCP
Wed Feb 14 03:39:16 AEST 1990


> 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)
----------------------------------------------------------------------------



More information about the Comp.std.c mailing list