[petsc-users] passing an object to function
Dominik Szczerba
dominik at itis.ethz.ch
Sat Oct 8 06:48:38 CDT 2011
> On Fri, Oct 7, 2011 at 11:09, Dominik Szczerba <dominik at itis.ethz.ch> wrote:
>>
>> Sorry, I could not conclude: so what signature to pass an object is
>> best/cleanest/most optimal for my C++ code?
>
> Prefer Vec
If I do so (instead of Vec& that I started with), I receive segfaults.
An example function:
foo(const Vec& v1, Vec& v2)
{
// allocate v2 and fill it it depending on v1)
}
Calling sequence;
Vec v1;
// create and fill v1;
Vec v2; // creation expected in foo()
foo(v1,v2);
// Now do VecGetArray on v2
This will work as expected only if the signature for foo is Vec&. When
replaced with Vec I get segfaults on VecGetArray trying to access v2
after calling foo, suggesting an attempt to access invalid memory
location.
Did I miss anything?
Many thanks, Dominik
More information about the petsc-users
mailing list