[vtk-developers] vtkImageData

Volpe, Christopher R (CRD) volpecr at crd.ge.com
Tue Jun 5 11:42:28 EDT 2001


Yes, this has been true in C as well as C++ since forever. "foo(int a[])" and "foo(int
a[<constant>])" are synonyms for "foo(int *a)". Since any array identifier used in the argument list
to a function call will decay to a pointer to the first element, there is no way to pass an array by
value. But using array syntax in the prototype helps make the intent of the API clear. 

|> -----Original Message-----
|> From: Charl P. Botha [mailto:c.p.botha at its.tudelft.nl]
|> Sent: Tuesday, June 05, 2001 11:34 AM
|> To: vtk-developers at public.kitware.com
|> Subject: Re: [vtk-developers] vtkImageData
|> 
|> 
|> On Tue, Jun 05, 2001 at 08:57:48AM -0400, Jeff Lee wrote:
|> > prototypes(interface) and their corresponding implementation.  One
|> > example is vtkImageData::GetDimensions(...).  The 
|> interface expects the
|> > argument to be an integer array, and the implementation expects an
|> > int*.  It is a mystery to me as to why other compilers 
|> don't complain
|> > about this (probably an acceptable built-in conversion for most
|> > compilers).  Anyhow, I think that it is good programming 
|> practice to
|> > make the prototype match the implementation.  In the case of
|> 
|> This is (afaik) _entirely_ acceptable.  In the case of "int 
|> a[3]", a is also
|> a pointer to the first element of the array, thus of type 
|> "int *".  From my
|> ISO C++ spec, page 58:
|> 
|> 4.2 Array-to-pointer conversion 
|> 1 An lvalue or rvalue of type array of N T or array of 
|> unknown bound of T
|> can be converted to an rvalue of type pointer to T.  The 
|> result is a pointer
|> to the first element of the array.
|> 
|> Does your compiler claim ISO compliance?
|> 
|> -- 
|> charl p. botha      | computer graphics and cad/cam 
|> http://cpbotha.net/ | http://www.cg.its.tudelft.nl/
|> 
|> _______________________________________________
|> vtk-developers mailing list
|> vtk-developers at public.kitware.com
|> http://public.kitware.com/mailman/listinfo/vtk-developers
|> 




More information about the vtk-developers mailing list