Undefined behavior when passing C++ objects to C routine -
I've found that if I pass in the context by the manufacturer I do this, it fixes the problem in A.cpp!
i.e. Update Actually I want to call some code from c ++. As explained in the C manual, to avoid using the global variable, "Futile * FDATA" is provided to receive additional information, if none, then tap it Pointing at Now I have to go through the "F" packing some C + objects and through this FDAATA logic, the way I could imagine that it was a class "Infops" Define, and pass it to C. Caratine My C ++ snippet (e.g. A CPP and BQP, A does not work properly, while B is fine): Now, I can compile (GCC) and run Example A For, weird, there are undefinded behaviors, sometimes it gives NaN, sometimes it gives very crazy numbers ... However, if I do this in the following way (eg B, Use points for the category) then use "new" in f, works fine! wondering why? Since I like the example A to B, in which I need "new" object ... What does get information (vector & lt; double & gt; and amp0; vector & lt; double & gt; & amp; arg1 ...) , but what is the reason ?
int f (unsigned nandy, unsigned npts, const double * x, zero * fdata, unsigned fdim, double * fval);
// example eg .cpp #include "Cubature.h" // c library which includes cubature #include "extern_cpp_class.hpp" // class InfoPass {public: extern_cpp_class obj1; Extern_cpp_class obj2; Extern_cpp_class obj3; Double ARR [3]; Information about obj1 {arg0, arg1}, obj2 {arg0, arg2}, obj3 {arg0, arg3} {}} (vector & lt; double & gt; arg 0, vector & lt; double & gt; arg1, vector & Lt; double & gt; arg2, vector & lt; double & gt; arg3); // The declaration of int f () and coupure () below is in c code int f (unsigned ndim, const double * x, zero * fdata, unsigned fdim, double * fval); Int main () {doing something} / information passes caps {arg0, arg1, arg2, arg3}; // Early cube (2, f, and cubaspass, 2, xmin, xmx, 1e5, 0, 1a -5, errorOPARED, output, and iglia); / *** with process output *** int} (unsigned nandi, const double * x, void * fdata, unsigned fdim, double * fval) {InfoPass * fcubpass = static_cast & lt; InfoPass * & gt; (Fdata); / *** works with fcubpass.obj1, .obj2 ... *** /}
extern_cpp_class do the items with their initial parameters? If they take their
vector logic in the references and store it, then you get annoyed with the original
A.cpp because logic is temporary copies that have been destroyed. Disallowing references - After the
cubpass the execution of the manufacturer has expired. On references to change, it must be ensured that the
extern_cpp_class object is
vector s has been created in the
main , which (Possibly) Unless you are out of the program (or at least as long as you are working with
cubpass ) in
B.cpp Constructors already receive references to such
vector s, so there is no problem.
Comments
Post a Comment