[petsc-users] passing an object to function

Dominik Szczerba dominik at itis.ethz.ch
Fri Oct 7 11:09:06 CDT 2011


Sorry, I could not conclude: so what signature to pass an object is
best/cleanest/most optimal for my C++ code? Or are they all fine, e.g.
Vec would pass address by value, Vec& would pass address by reference,
Vec* would pass the pointer, none of them copying the heavy data?

On Fri, Oct 7, 2011 at 2:17 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> On Fri, Oct 7, 2011 at 04:45, Dominik Szczerba <dominik at itis.ethz.ch> wrote:
>>
>> I need to do something with - say - a Vec in a function but obviously
>> do not want to copy by value. Should the signature be foo(Vec) or
>> foo(Vec&)?
>
> PETSc does not use C++ internally.
>
>>
>> I see Vec is a pointer in itself, so Vec should suffice,
>> but in many Petsc functions I see Vec& signatures,
>
> No, you see some Vec* signatures, not Vec&. Vec* is used when a new Vec is
> created, if the function needs to modify the pointer, or if the argument is
> an array of Vecs.


More information about the petsc-users mailing list