Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Assigning variables

Assigning variables
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2002
Status: Offline
Reply With Quote
Apr 15, 2002, 10:29 PM
 
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.

UInt32 currentTime, lastTime, duration;

lastTime = currentTime; // changes the pointing location of pointer, rather than assigning the value

lastTime = &currentTIme; // points to a memory location, but i still can't get the int from it.....


any suggestions would be great, thanks
     
Registered User
Join Date: May 2001
Location: Cambridge, UK
Status: Offline
Reply With Quote
Apr 16, 2002, 10:12 PM
 
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 = &currentTIme; // 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 = &currentTime;
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 ]
     
Fresh-Faced Recruit
Join Date: Apr 2002
Status: Offline
Reply With Quote
Apr 18, 2002, 11:23 PM
 
actually that helped a lot, thanks again, let me know if i can help in anyway.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:47 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2