FAQ
Any ideas on how to properly do this?

/*
double* the_c_function()
{
      // bunch of stuff happens to populate values[]

      double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
function

      printf("an element value: %lf\n", values_ptr[3]);

      return values_ptr;
}
*/
import "C"


func main () {
      returned_double_array = C.the_c_function()

      //how do I get/read the elements of returned_double_array ?
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Gustavo Niemeyer at Feb 5, 2014 at 6:28 am

    On Wed, Feb 5, 2014 at 4:14 AM, Curtis Paul wrote:
    Any ideas on how to properly do this?
    Something along these lines: http://play.golang.org/p/ekbp7xHwQx


    gustavo @ http://niemeyer.net

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Minux at Feb 5, 2014 at 6:36 am

    On Wed, Feb 5, 2014 at 1:14 AM, Curtis Paul wrote:

    Any ideas on how to properly do this?

    /*
    double* the_c_function()
    {
    // bunch of stuff happens to populate values[]

    double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
    function

    printf("an element value: %lf\n", values_ptr[3]);

    return values_ptr;
    }
    */
    import "C"


    func main () {
    returned_double_array = C.the_c_function()

    //how do I get/read the elements of returned_double_array ?
    }
    You can convert it to a Go slice of float64.

    https://code.google.com/p/go-wiki/wiki/cgo

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Curtis Paul at Feb 6, 2014 at 2:22 am
    So far the examples have been what's documented, and doesn't really answer
    my question. At least not in a way I understand.
    On Tuesday, February 4, 2014 11:14:46 PM UTC-7, Curtis Paul wrote:

    Any ideas on how to properly do this?

    /*
    double* the_c_function()
    {
    // bunch of stuff happens to populate values[]

    double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
    function

    printf("an element value: %lf\n", values_ptr[3]);

    return values_ptr;
    }
    */
    import "C"


    func main () {
    returned_double_array = C.the_c_function()

    //how do I get/read the elements of returned_double_array ?
    }
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Curtis Paul at Feb 6, 2014 at 3:47 am
    So I'm able to get the elements of the array, but they are scientific
    notiation, and when I try doing an fmt.Println("%2.1f",Cdoublefield) I get
    0.0 for any of the values.

    fmt.Println(Cdoublefield) prints 8.637783107073355e-270 which is supposed
    to be 23.2 ...why would I get 0.0 instead of 23.2?

    On Tuesday, February 4, 2014 11:14:46 PM UTC-7, Curtis Paul wrote:

    Any ideas on how to properly do this?

    /*
    double* the_c_function()
    {
    // bunch of stuff happens to populate values[]

    double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
    function

    printf("an element value: %lf\n", values_ptr[3]);

    return values_ptr;
    }
    */
    import "C"


    func main () {
    returned_double_array = C.the_c_function()

    //how do I get/read the elements of returned_double_array ?
    }
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Curtis Paul at Feb 6, 2014 at 4:55 am
    No, it's just returning the correct value...it's not a scientific notation
    representation of the returned value, it's just bad data.

    Does anyone know if C lang can return a double array to Go correctly? Can
    Go interpret a C lang double array?

    I have not been able to find any examples of doing this anywhere.....I see
    string and integer examples....but no float or double examples...
    On Tuesday, February 4, 2014 11:14:46 PM UTC-7, Curtis Paul wrote:

    Any ideas on how to properly do this?

    /*
    double* the_c_function()
    {
    // bunch of stuff happens to populate values[]

    double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
    function

    printf("an element value: %lf\n", values_ptr[3]);

    return values_ptr;
    }
    */
    import "C"


    func main () {
    returned_double_array = C.the_c_function()

    //how do I get/read the elements of returned_double_array ?
    }
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Curtis Paul at Feb 6, 2014 at 5:01 am
    I mean it's not returning the correct double value
    On Wednesday, February 5, 2014 9:55:53 PM UTC-7, Curtis Paul wrote:

    No, it's just returning the correct value...it's not a scientific notation
    representation of the returned value, it's just bad data.

    Does anyone know if C lang can return a double array to Go correctly? Can
    Go interpret a C lang double array?

    I have not been able to find any examples of doing this anywhere.....I see
    string and integer examples....but no float or double examples...
    On Tuesday, February 4, 2014 11:14:46 PM UTC-7, Curtis Paul wrote:

    Any ideas on how to properly do this?

    /*
    double* the_c_function()
    {
    // bunch of stuff happens to populate values[]

    double *values_ptr = mxGetPr(values[0]); //this is a Matlab c
    function

    printf("an element value: %lf\n", values_ptr[3]);

    return values_ptr;
    }
    */
    import "C"


    func main () {
    returned_double_array = C.the_c_function()

    //how do I get/read the elements of returned_double_array ?
    }
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan Kortschak at Feb 6, 2014 at 5:18 am

    On Wed, 2014-02-05 at 21:01 -0800, Curtis Paul wrote:
    I mean it's not returning the correct double value
    You're not passing the double to foo, so it's getting uninitialised
    data.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan Kortschak at Feb 6, 2014 at 5:20 am
    http://play.golang.org/p/sijNOPw6o4 sorry.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Curtis Paul at Feb 6, 2014 at 5:23 am
    I got it now, makes sense....I appreciate the help, thanks!
    On Wednesday, February 5, 2014 10:20:41 PM UTC-7, kortschak wrote:

    http://play.golang.org/p/sijNOPw6o4 sorry.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 5, '14 at 6:14a
activeFeb 6, '14 at 5:23a
posts10
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase