Note that there are some explanatory texts on larger screens.

plurals
  1. POBad pointer type with a typedef
    primarykey
    data
    text
    <p>I'm having troubles when calling a function taking a pointer to a string as a parameter. I need to get an Element's name.</p> <pre><code>// method void getStringFromCsv( char ** str ); </code></pre> <p>Let me introduce the structures I'm working with (not written by me and part of a much bigger project, I can't modify them). </p> <pre><code>// typedefs typedef char T_CHAR64[64]; typedef T_CHAR64 T_SYMBOL; // generic element typedef struct Element { T_SYMBOL name; } T_Element; // csv element typedef struct CsvElement { Element * pElement; int id; } T_csvElement; </code></pre> <p>So, basically, I thought I would call the function like this :</p> <pre><code>T_Element * pData; // Not null, filled earlier getStringFromCsv( &amp;pData-&gt;pElement-&gt;name ); </code></pre> <p>But this doesn't work (warning: passing argument 1 of ‘STR_toCsv’ from incompatible pointer type). I'm using gcc with NetBeans 6.8. </p> <p>I tried many things...</p> <pre><code>T_SYMBOL foo = "foo"; T_SYMBOL * pFoo = &amp;foo; getStringFromCsv( pDef-&gt;name, &amp;pFoo ); // error : passing from incompatible pointer type T_CHAR * pBar = &amp;foo; // error : init from incompatible pointer type T_CHAR * pBaz = &amp;(foo[0]); // OK getStringFromCsv( pDef-&gt;name, &amp;pBaz ); // OK T_SYMBOL * pFooTest = &amp;(foo[0]); // error : init from incompatible pointer type </code></pre> <p>...but ended up casting name to a char ** :</p> <pre><code>getStringFromCsv( (char**) &amp;pData-&gt;pElement-&gt;name ); </code></pre> <p>What is wrong with my code ? Basically, SYMBOL = CHAR *, right ? Why is SYMBOL* != CHAR** ? I'm pretty sure I'm missing something simple but right now... Nothing came.</p> <p><strong>EDIT</strong> Here is getStringFromCsv :</p> <pre><code>void getStringFromCsv( char ** data ) { // pDesc is defined and not null csvDescriptorCat( pDesc, *data); csvDescriptorCat( pDesc, "\t"); } void csvDescriptorCat( CsvDescriptor * pDesc, char* str) { int len; if( str != NULL) { len = strlen(str); strcpy( &amp;pDesc-&gt;line[pDesc-&gt;pos], str); pDesc-&gt;pos += len; } } </code></pre>
    singulars
    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.
 

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