To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 942
941  |  943
Subject: 
Re: Just some really basic questions...
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Wed, 31 Jan 2001 10:50:27 GMT
Viewed: 
2153 times
  
In lugnet.robotics.rcx.nqc, Dean Husby writes:

Your example did as I have stated. Global variables are global across all • program
slots.

Dean,

you are right and meanwhile I could test it.
However, the definition for the global variables must be in the SAME ORDER
order for both of the programs.

If you would do this:

SLOT 1:
int testvar1 = 1;
int testvar2 = 2;
int globvar1 = 3;
int globvar2 = 4;
task main ()
{
  SelectProgram (4); // program 4 = slot 5
}
SLOT 5:
int globvar1;
int globvar2;
task main () {
  SetUserDisplay (globvar1, 0);
  Wait (100);
  SetUserDisplay (globvar2, 0);
  Wait (100);
}

your output will be 1 and 2 and not 3 and 4 as one could expect. The reason is
clear when you look at the compiled programs:

SLOT 1:
setv   var[0], 1
setv   var[1], 2
setv   var[2], 3
setv   var[3], 4
...
prgm   4

SLOT 5:
...
disp   0, var[0]
wait   100
disp   0, var[1]
wait   100

That means, global variables that should be shared between programs in
different slots must be in the SAME LOCATION and ORDER.

A Note for DAVE BAUM:
It would be good to make some statements about the above in the NQC
documentation.

(Note only for oldies like me: this is the same as a "Common Block" in old
Fortran programming, where values were shared between different main programs
that were executed consecutively).

Best regards and happy GVS   :-)
Bernd

GVS: Global Variable Sharing



Message has 1 Reply:
  Re: Just some really basic questions...
 
(...) Thank you Frank, I had forgotten about that. Thank you for bringing it up. This info will save considerable suffering in future! Dean -- Coin-Op's For Sale!: (URL) Lego Workshop: (URL) Lego Club: (URL) (24 years ago, 31-Jan-01, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Re: Just some really basic questions...
 
(...) Your example did as I have stated. Global variables are global across all program slots. Dean -- Coin-Op's For Sale!: (URL) Lego Workshop: (URL) Lego Club: (URL) (24 years ago, 30-Jan-01, to lugnet.robotics.rcx.nqc)

9 Messages in This Thread:


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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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