Hi Ashwin,
I am not observing the copying behavior that you are talking about. From your example, replacing "class" with
"record" and "var a_obj = A;" with "var a_obj = new A(int);", here is what I get with the
compiler on our master branch as of now:
static void foo(void) {
A_int64_t a_obj;
A_int64_t this5;
A_int64_t wrap_call_tmp;
A_int64_t ret_tmp;
_ref_A_int64_t ret_to_arg_ref_tmp_ = NULL;
_ref_int64_t call_tmp2 = NULL;
c_ptr_int64_t call_tmp3 = NULL;
(&this5)->value = INT64(0);
(&this5)->value = INT64(0);
ret_to_arg_ref_tmp_ = &ret_tmp;
_construct_A(INT64(0), &this5, ret_to_arg_ref_tmp_);
wrap_call_tmp = ret_tmp;
a_obj = wrap_call_tmp;
call_tmp2 = &((&a_obj)->value);
call_tmp3 = c_pointer_return(call_tmp2);
c_func(((c_void_ptr)(call_tmp3)));
return;
}
This looks like it does what you want.
If you are observing a different behavior, could you please open an GitHub
issue for that?
https://github.com/chapel-lang/chapel/issues/new
Vass
On 08/01/17 16:57, Aji, Ashwin wrote:
Hi,
In Chapel, how can I pass a reference (c pointer style) to a field of a
record/class to an external C function.
For example,
extern proc c_func(val_ptr: c_void_ptr);
class A {
type retType;
var value: retType;
// constructors not shown but they are the usual simple ones
}
proc foo() {
var a_obj = A;
c_func(c_ptrTo(a_obj.value));
// codegen first creates a copy of a_obj and then passes pointer to the
copy's value field.
// A a_obj_copy = a_obj; // copy by value
// c_func(&(c_obj_copy.value));
// But, I want the below:
// c_func(&(c_obj.value));
}
Regards,
Ashwin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers