Note that there are some explanatory texts on larger screens.

plurals
  1. POCasting long int as a struct pointer
    primarykey
    data
    text
    <p>I know this is a rather noobish question, but no amount of googling or permutations of code seem to work.</p> <p>I have a structure which is defined like this.</p> <pre><code>typedef struct { int rate; int duration; } DummyStructure; </code></pre> <p>Now, i try to use code similar to this.</p> <pre><code>// DummyStructure* structure; DummyStructure* structure2; long int point; // structure = (DummyStructure*)malloc(sizeof(DummyStructure)); structure-&gt;rate = 19; structure-&gt;duration = 92; point = (long int)&amp;structure; // now i'd like to set structure2 to the same memory location as 1. // point is the 8-byte int location (i assume?) of structure. // so naturally i'd assume that by casting as a DummyStructure pointer // that long int would act as a pointer to that 1. // It doesn't. structure2 = (DummyStructure*)point; </code></pre> <p>I stress that i've tried every permutation of ** and * that is possible. I just don't get it. Either it doesn't compile, or it does, and when it does i end up with seemingly random numbers for the fields contained in structure2. I assume that somehow i'm winding up with an incorrect memory location, but how else can you get it except from using the &amp;?</p> <p>I have the memory location, right? How do i set the structure to that location?</p> <p>EDIT; I forgot to mention (and subsequent answers have asked) but i'm intending to use this to wrap libvorbis for jni. Using jni means that i can't pass-back any of the structs that libvorbis does, but it requires them for its core functions. Therefore my wrapper is going to use vorbis directly to make the structs, and i pass back to java the pointer to them so that when i need to fill the buffer with more sound, i can simply re-reference the struct objects from the integer value of the pointer.</p>
    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