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