Global Variables
nicoladicosmo
Posts: 12
Hi all,
I'm writing a netlink program which has the following components:
- main.axs
- data.axi
- ipmodule.axs
both axs files include `data.axi`, without any problem.
I've declared the following variable into the data.axi file :
define_variable
slong globalCounter = -1;
So I can refer to `globalCounter` into each part of my program.
But, If I write :
BUTTON_EVENT[dvTP,19]
{
PUSH:
{
SEND_COMMAND dvTP, "'@TXT',2,FORMAT('"Global counter is %d"',globlaCounter)";
}
}
into the main file, the value shown on my TP is the value assigned to globalCounter into `define start` section,
if I put the same code into ipmodule.axs file, which is modified at runtime, the right value is shown.
Can someone tell me why I cannot write event handler into main.axi file?
Can someone tell me how works the global variables?
Tahnks in advance
Best regards ND
I'm writing a netlink program which has the following components:
- main.axs
- data.axi
- ipmodule.axs
both axs files include `data.axi`, without any problem.
I've declared the following variable into the data.axi file :
define_variable
slong globalCounter = -1;
So I can refer to `globalCounter` into each part of my program.
But, If I write :
BUTTON_EVENT[dvTP,19]
{
PUSH:
{
SEND_COMMAND dvTP, "'@TXT',2,FORMAT('"Global counter is %d"',globlaCounter)";
}
}
into the main file, the value shown on my TP is the value assigned to globalCounter into `define start` section,
if I put the same code into ipmodule.axs file, which is modified at runtime, the right value is shown.
Can someone tell me why I cannot write event handler into main.axi file?
Can someone tell me how works the global variables?
Tahnks in advance
Best regards ND
0
Comments
Can you post the part of your code where you declare the includes?
That might give us a clue as to how to help.
e
By including the data.axi in the 2 .axs file you merely included the contents of the .axi and thus created 2 instances of the contents that are completely independant of each other. They're actually different values since the constants, variable, functions or what have you are flagged with an id that makes them unique to the file they are included into. So if your data.axi has a variable named nVar for instance when it's included in the main compiled code it may be flagged by the compiler as main.nVar or something while in the ipmodule.axs it may be ipmodule.nVar so they are referencesd as seperate entities by the processor not the same so they don't share values.
thanks for you answers.
If I understand I cannot declare a global variable shared from more module (axs files) into an include file, because the compiler cannot discriminate which of them has been involved.
A way to share some variables between modules is pass them as module parameters.
But if I declare the variable just into an include file, why I can see all variables already delcared in all program parts?
Any way, I attach my code so if you have time, can see it, and give me some help to better use netlink environment.
Best Regards
ND
DATA.AXI
PROGRAM_NAME='data'
#if_not_defined __DATA__
#define __DATA__
define_variable
slong globalCounter = -1;
#end_if
So you can see them all but they are all really different.
Not really, meaning the names are not used (except for debugging). It works similar to how you described it but the technical details are quite a bit different.
The term "global variable" is not particularly meaningful with modules. It may be global in terms of the main code, or global in terms of the module, but unless it's declared in the main code and passed as a parameter, it's never global to both. Don't be confused by the fact that the debugger sees them with the same name. They are different variables. The debugger doesn't inherit the unique token generated when the module is initialized (which I understand is the variable name plus the instance label of the module). You might think you are looking at one variable, but are really looking at another.
ND