Note that there are some explanatory texts on larger screens.

plurals
  1. POC Segmentation fault in struct. Code translated from Matlab->C with Matlab Coder
    primarykey
    data
    text
    <p>I am translating some Matlab functions to C with Matlab Coder. Everything works to the point, where i want to return an array(transposed vector) from my function.</p> <p>In Matlab I have a function:</p> <pre><code>function returnedArray = myFun(input arguments) &lt;function code&gt; </code></pre> <p>This call to the function in C gets translatet to:</p> <pre><code>void myFun(input arguments, emxArray_realT *returnedArray) &lt;function code&gt; </code></pre> <p>emxArray_real_T is a struct, that was generated by Matlab Coder:</p> <pre><code>struct emxArray_real_T { real_T *data; int32_T *size; int32_T allocatedSize; int32_T numDimensions; boolean_T canFreeData; }; </code></pre> <p>And real_T, int32_T... are created generic type definitions:</p> <pre><code>typedef double real_T; </code></pre> <p>I call this myFun from main:</p> <pre><code>struct emxArray_real_T *result = malloc(sizeof(struct emxArray_real_T)); myFun(input arguments, result); </code></pre> <p>When i run this, i get an error saying: Segmentation fault. gdb gave me this:</p> <pre><code>Program received signal SIGSEGV, Segmentation fault at: 99643: i0=retArray-&gt;size[0]; p retArray $1 = (emxArray_real_T *) 0xc1d010 p retArray.size $2 = (int32_T *) 0x0 p retArray.size[0] Cannot access memora ar adress 0x0 </code></pre> <p>Am i doing something wrong in my main function? I hope so, because translated code from Matlab in C is a mess, or maybe just for me as a novice. The code works fine, if I translate and compile it in C without the return value.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload