Originally posted by Sid23Nova:
<STRONG>I was trying to figure out a duration of time by storing the last measured time and subtracting it from the current time in Carbon. I am unable to assign the current time to last time after the calculation for some reason. I think it is a problem concerning pointers.
</STRONG>
I've never programmed in carbon, so somebody correct me if I'm wrong, but you do appear to have a problem with pointers.
UInt32 currentTime, lastTime, duration;
lastTime = currentTime; // changes the pointing location of pointer, rather than assigning the value
No. This assignement copies the value of currentTime into lastTime. If you want to "change the pointing location" instead, the variables should be declared as pointers.
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
UInt32 *currentTime, *lastTime;
lastTime = currentTime;
</font>[/code]
UInt32 currentTime, lastTime, duration;
lastTime = ¤tTIme; // points to a memory location, but i still can't get the int from it.....
This time lastTime would have to be declared as a pointer to a UInt32 and currentTime declared an actual UInt32. To get the int from the address, you have to use the * operator:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
UInt32 currentTime, *lastTime;
UInt32 value;
lastTime = ¤tTime;
value = *lastTime;
</font>[/code]
I'm sorry if this isn't very clear. I suggest you read up on C pointer - there are lots of tutorials about on the web. A quick search on google turned up the following:
C Programming - Pointers
Matt
[ 04-16-2002: Message edited by: mattcunnane ]