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 / 1784
1783  |  1785
Subject: 
Re: pass by refrence or value?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 25 Mar 2001 12:42:42 GMT
Viewed: 
1425 times
  
Some basic facts about C semantics:

As already stated, globals MUST be volatile if they are accessed by more
than one thread, otherwise reads and writes can be out of sync.

What are the types of the variables involved?  Scalar values like integers
are always passed by value, i.e. a new copy in the called function.  The
same goes for structures, but NOT for arrays.

The use of "memcpy" indicates that the object being passed in large, and
thus I suspect an array.  Arrays are always passed as a pointer, since
copying them is considered too expensive to do automatically.

If you want an array that is passed by value, wrap it inside a struct.

/jakob



Message is in Reply To:
  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