<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>basic pointer question</title></head><body>
<div>ok,</div>
<div><br></div>
<div>...it's time I need to admit I'm a self-taught hobby programmer,
cuz I've run into (perhaps) a basic problem that I can't seem to
figure out, having to do with pointers and such...</div>
<div><br></div>
<div>...here is the original version of the function:</div>
<div><font size="-1" color="#760F50">void</font><font size="-1"
color="#000000"> moff_defpoints(ubyte * p)</font></div>
<div><font size="-1" color="#000000">{<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab></font><font
size="-1" color="#760F50">int</font><font size="-1" color="#000000">
n;</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">int</font><font
size="-1" color="#000000"> nverts = w(p</font><font size="-1"
color="#0000FF">+8</font><font size="-1"
color="#000000">);</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">int</font><font
size="-1" color="#000000"> offset = w(p</font><font size="-1"
color="#0000FF">+16</font><font size="-1"
color="#000000">);</font></div>
<div><font size="-1" color="#000000"><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab>ubyte *
normcount = p</font><font size="-1" color="#0000FF">+20</font><font
size="-1" color="#000000">;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vector *src =
vp(p+offset);<br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp; </x-tab>Assert( nverts &lt; MAX_POLYGON_VECS
);<br>
<x-tab>&nbsp;&nbsp;&nbsp; </x-tab></font><font size="-1"
color="#236E25">// Assert( nnorms &lt; MAX_POLYGON_NORMS );</font><br>
<font size="-1" color="#000000"></font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">for</font><font
size="-1" color="#000000"> (n=</font><font size="-1"
color="#0000FF">0</font><font size="-1" color="#000000">; n&lt;nverts;
n++ )<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>{</font></div>
<div><font size="-1" color="#000000"><br></font></div>
<div><font size="-1"
color="#000000"
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font
><font size="-1" color="#236E25"> Interp_verts[n] = src;</font></div>
<div><font size="-1"
color="#000000"
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
src += normcount[n]</font><font size="-1"
color="#0000FF">+1</font><font size="-1"
color="#000000">;</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>}</font></div>
<div><font size="-1" color="#000000">}</font></div>
<div>...this seems to step through a set of vertex vectors
(xyz.x,y,z)and assign them to an externally declared global vector
&quot;Interp_verts[n]&quot;...ByteSwapping needs to be done on all
data coming from the passed in pointer &quot;p&quot;, so I initially
tried swapping the x,y, and z floats passed into the &quot;src&quot;
vector by doing src-&gt;xyz.x = LoadLEFloat( &amp;src-&gt;xyz.x
);</div>
<div><br></div>
<div>...then I noticed that by doing this, I'm actually changing the
value in the passed in pointer, and so future references get swapped
multiple times, which isn't good!</div>
<div><br></div>
<div>So, I tried to create a local &quot;buffer&quot; vector that
would hold the swapped floats, put them into a buffer vector, then
pass that to the global vector Interp_verts[n]...but this isn't
happening, and I'm not sure where I've gone wrong?&nbsp; Can someone
get me straight on this?</div>
<div><br></div>
<div><font size="-1" color="#760F50">void</font><font size="-1"
color="#000000"> moff_defpoints(ubyte * p)</font></div>
<div><font size="-1" color="#000000">{<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </x-tab></font><font
size="-1" color="#760F50">int</font><font size="-1" color="#000000">
n;</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">int</font><font
size="-1" color="#000000"> nverts = SDL_SwapLE32( w(p</font><font
size="-1" color="#0000FF">+8</font><font size="-1"
color="#000000">));</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">int</font><font
size="-1" color="#000000"> offset = SDL_SwapLE32( w(p</font><font
size="-1" color="#0000FF">+16</font><font size="-1"
color="#000000">));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="-1"
color="#236E25"> //int nverts = w(p+8);</font><font size="-1"
color="#000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="-1"
color="#236E25"> //int offset = w(p+16);</font><font size="-1"
color="#000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font size="-1"
color="#760F50"> float</font><font size="-1" color="#000000"><x-tab>&nbsp;
</x-tab>srcx, srcy, srcz;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vector *tmp;<br>
<br>
<x-tab>&nbsp;&nbsp; </x-tab>ubyte * normcount = p</font><font
size="-1" color="#0000FF">+20</font><font size="-1"
color="#000000">;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vector *src =
vp(p+offset);<br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp; </x-tab>Assert( nverts &lt; MAX_POLYGON_VECS
);<br>
<x-tab>&nbsp;&nbsp;&nbsp; </x-tab></font><font size="-1"
color="#236E25">// Assert( nnorms &lt; MAX_POLYGON_NORMS
);</font><font size="-1" color="#000000"><br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab></font><font size="-1" color="#760F50">for</font><font
size="-1" color="#000000"> (n=</font><font size="-1"
color="#0000FF">0</font><font size="-1" color="#000000">; n&lt;nverts;
n++ )<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>{</font></div>
<div><font size="-1"
color="#000000"
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
srcx = LoadLEFloat( &amp;src-&gt;xyz.x );<x-tab>&nbsp;
</x-tab></font></div>
<div><font size="-1"
color="#000000"
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
srcy = LoadLEFloat( &amp;src-&gt;xyz.y );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
srcz = LoadLEFloat( &amp;src-&gt;xyz.z );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tmp-&gt;xyz.x = srcx;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tmp-&gt;xyz.y = srcy;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tmp-&gt;xyz.z = srcz;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font
><font size="-1" color="#236E25"> //Interp_verts[n] =
src;</font><font size="-1" color="#000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Interp_verts[n] = tmp;</font></div>
<div><font size="-1"
color="#000000"
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
normcount[n] = SDL_SwapLE16( normcount[n] );</font></div>
<div><font size="-1" color="#000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; src
+= normcount[n]</font><font size="-1" color="#0000FF">+1</font><font
size="-1" color="#000000">;</font></div>
<div><font size="-1"
color="#000000"><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</x-tab>}<br>
}</font></div>
<div><br></div>
<div>Tanx,</div>
<div>jamie</div>
</body>
</html>