var_extern
#1022
Replies: 1 comment 2 replies
-
Var_extern is a really bad practice, and should have never been added to the language. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
in our structure text code we have one variable declaration block known as, var_extern whose behaviour is same as var_global.
since at lot of places in our structure text project specially in programs, are using var_extern block, so is there any way inside source code of rusty we can enable support for this variable declaration block?
Note : i have attached sample programs, in which both programs inProgram.st & outProgram.st shares extern/global variable
called gnExternalIf.
------------------------------------------------------------------inProgram.st----------------------------------------------------------------
program inProgram
var
fb1 : function_block1; (checks persistence)
fb2 : function_block2; (Plays around with var_in_out and var_const)
printstr : PRINT_STRING;
asign1 : dint ;
asign2 : dint ;
asign3 : dint ;
end_var
if gnExternalIf = 0 then
asign1 := gnExternalIf + 1;
asign2 := gnExternalIf + 2;
asign3 := gnExternalIf + 3;
fb1();
elsif gnExternalIf = 1 then
fb1(I2 := asign1);
else
asign2 := gnExternalIf + 2;
asign3 := gnExternalIf + 3;
fb1();
end_if;
fb2(IO2 := asign2,
IO1 := asign3
);
printstr(CI := TRUE,
PRINTER := fb1.Q2,
IN := 'value of fb1.Q2');
printstr(CI := TRUE,
PRINTER := fb2.IO1,
IN := 'value of fb2.IO1');
printstr(CI := TRUE,
PRINTER := fb2.IO2,
IN := 'value of fb2.IO2');
printstr(CI := TRUE,
PRINTER := fb2.Q3,
IN := 'value of fb2.Q3');
printstr(CI := TRUE,
PRINTER := fb2.Q4,
IN := 'value of fb2.Q4');
printstr(CI := TRUE,
PRINTER := gnExternalIf,
IN := 'In inProgram(), gnExternalIf ');
gnExternalIf := gnExternalIf + 1;
end_program
----------------------------------------------------------------outProgram.st----------------------------------------------------------------
program outProgram
var_extern
gnExternalIf : dint; (* defaults to zero *)
end_var
var
prtString : PRINT_STRING; (* prints to the Controller panel of the emulator *)
passCount : bool := false;
end_var
if
gnExternalIf = 5
then
prtString (CI := TRUE, PRINTER := 9, IN := 'Pass');
elsif
gnExternalIf = 6
then
prtString (CI := TRUE, PRINTER := 1, IN := 'Another Pass');
passCount := true;
else
prtString (CI := TRUE, PRINTER := 2, IN := 'FAIL');
end_if;
if
passCount = true
then
case gnExternalIf of
0:
prtString (CI := TRUE, PRINTER := 3, IN := 'case 0');
1:
prtString (CI := TRUE, PRINTER := 4, IN := 'case 1');
else
prtString (CI := TRUE, PRINTER := 5, IN := 'case default');
end_case;
else
prtString (CI := TRUE, PRINTER := 6, IN := 'passCount FAIL');
end_if;
prtString(CI := TRUE,
PRINTER := gnExternalIf,
IN := 'In outProgram(), gnExternalIf ');
gnExternalIf := gnExternalIf + 1;
end_program
Beta Was this translation helpful? Give feedback.
All reactions