To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 1634
1633  |  1635
Subject: 
pass by refrence or value?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 18 Jan 2001 00:18:37 GMT
Viewed: 
1409 times
  
Hi all,

  i have a slight problem with legosv0.2.5 . The program code on the rcx is set
up so that there is serverall callback methods which get called when a message
comes in on the particular port for that object or class. These callback
methods set that values contained in the message into global variables so that
a thread can watch for them to be changed and then calls the appropriate method
to do something. These values are passed into the methods so that if the global
variables is changed the local copy will not be.

This worked for a while, but when i added a bit of extra code to a particular
method that was being called from the thread, the copy of the variable being
passed into the method had changed inside the method from what it was when it
was passed in.

My question is, is there a possibility that this variable is being passed by
refrence instead of passed by value?

all i have to do to stop this from happening is put in a memcpy at the
begining of the method to actually copy the parameter to a local variable.

what i also found when i was debugging my code was that if i commented out the
last half of the method it would work fine without the memcpy. The only
explaination i could come up with was that the process scheduling was on a
shortest process next algorithm and with the extra code in the method it was
being interupted to allow another thread to process which changed the value of
the global variable which affected the passed in value if it was passed by
refrence!!

can someone please fill me in on what i am misunderstanding!
it would be greatly appreciated.

cheers ross



Message has 1 Reply:
  Re: pass by refrence or value?
 
Did you care to declare your global variable as volatile? this (normaly) prevent the compiler to optimize memory access and force it to read the actual value of the variable each time it need it ( instead of localy storing it in a register wich will (...) (24 years ago, 18-Jan-01, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR