python - Swig tool and C++. Being too clever -
http://www.swig.org/papers/pytutorial98/pytutorial98.pdf comes above link:
i know old publication possible information outdated.
i ask:
"seems work fine c++ if aren't being clever" mean, clever?
is there known situation/case shuold careful programming c++ modules , extending python using swig
tool?
the slide strange , misleading. swig not transform pass-by-value pass-by-reference @ all. let me try clarify example:
let's in example have c++ function
double dot_product(vector a, vector b);
now in plain c++ (no swig, no wrapping) may use function in following examples:
1.
vector = vector(1,0); vector b = vector(0,1); double 0 = dot_product(a, b);
2.
vector *a = new vector(1,0); vector *b = new vector(0,1); double 0 = dot_product(*a, *b);
in both cases, function in fact called in same way using call-by-value.
swig wraps objects structure contains pointer object, under hood swig passes pointers around everything, , therefore uses syntax in second example. there no conversion / transformation of call semantics going on whatsoever.
to answer questions:
"seems work fine c++ if aren't being clever" mean, clever?
i have no idea. stated in answer, joke.
is there known situation/case shuold careful programming c++ modules , extending python using swig tool?
this broad question, , there pitfalls, related memory management. however, particular "transformation" not issue.
for reference, here relevant entry in swig manual. note worded differently: function transformed accept pointers. nothing said "call semantics" (since non-issue).
Comments
Post a Comment