On Sat, 15 May 2004 14:53:03 +0200, Michael Birkmose
<birkmose@cs.auc.dk> wrote:
[color=blue][color=green]
> > However... shouldn't "pointer to array of int" be written as "int []"
> > or its equivalent "int *"? Thus the declaration cdecl returned seems
> > wrong! What it returned seems to me like an array of pointers to int.
> >
> > Someone familiar with cdecl comment please?[/color]
>
> int[] is const pointer to int I guess?
>[/color]
No. Normally, it is an array (of unspecified bound) of int; you cannot
_define_ (allocate) an object of that type (unless with an initializer
that supplies the bound), and thus cannot declare an automatic object
because such a declaration is always a definition; but you can use
such a declaration to refer to an object defined suitably elsewhere.
Any array lvalue (in C99 or rvalue!) when used in an expression with a
few exceptions "decays" (converts) to a pointer _rvalue_; rvalues
aren't qualified <OT> except in C++ for classes </> so it is neither
const or non-const, but you can't assign to an rvalue and some people
may think of that as 'const' or 'const-like' or 'constant'.
_As a function parameter_ only, any top-level array declaration is
"adjusted" or "rewritten" to pointer, so this declares a pointer to
int. Not a const pointer; it can be reseated (assigned to point
elsewhere) within its scope (the function body), although doing so may
be confusing and therefore undesirable.
See section 6 of the FAQ, at the usual places and
http://www.eskimo.com/~scs/C-faq/top.html .
[color=blue]
> However int (*foo)[] is pointer to int array (ie pointer to const
> pointer).
>[/color]
No, it's a pointer to array (of unspecified bound) of int. There is no
pointer to pointer (qualified or not) anywhere. Treating pointer to
array as if it were pointer to pointer, or vice versa, will produce
completely bogus results and very likely traps.
See section 6 of the FAQ.
[color=blue]
> So there is nothing wrong with the cdecl declaration I think.
> If you wanted to get an array of pointers to int you would do
> int *a[]
>[/color]
Now _that_ is right.
- David.Thompson1 at worldnet.att.net