Patrice,
In actuality LOCAL in bc9 works the same as PowerBASIC. Why the static I don't know but the results are the
same although the initialization each time the function is called is overhead that might want to be considered.
Note the AS type may also follow the var as in:
Raw I2 As Integer
From the help file:
A variable dimensioned with DIM or LOCAL in a subroutine or function retains the value on exit,
but will lose it on re-entry due to the automatic initialization.
James
This bc9 line
LOCAL AS Integer I1
produces this c code
static int I1;
memset(&I1,0,sizeof(I1));
These are 4 different ways to declare variables.
here is bc9 sample code
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Test LOCAL,RAW
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$ONEXIT "GWGCC.BAT $FILE$ -m32 con"
Sub DoTest()
LOCAL AS Integer I1
RAW AS Integer I2
Raw As Integer I3=0
STATIC As Integer I4
Print "I1 = ", I1
PRINT "I2 = ", I2
PRINT "I3 = ", I3
PRINT "I4 = ", I4
PRINT "----------"
I1 = 1
I2 = 2
I3 = 3
I4++
PRINT "I1 = ", I1
PRINT "I2 = ", I2
PRINT "I3 = ", I3
PRINT "I4 = ", I4
End Function
'==============================================================================
Function main(argc As Integer,argv As PCHAR ptr ) As Integer
Raw As Integer i
For i = 1 To 3
DoTest()
PRINT "********"
Next
Pause
End Function
c translation:
SNIP
void DoTest (void)
{
static int I1;
memset(&I1,0,sizeof(I1));
int I2;
int I3=0;
static int I4;
printf("%s% d\n","I1 = ",(int)I1);
printf("%s% d\n","I2 = ",(int)I2);
printf("%s% d\n","I3 = ",(int)I3);
printf("%s% d\n","I4 = ",(int)I4);
printf("%s\n","----------");
I1= 1;
I2= 2;
I3= 3;
I4++;
printf("%s% d\n","I1 = ",(int)I1);
printf("%s% d\n","I2 = ",(int)I2);
printf("%s% d\n","I3 = ",(int)I3);
printf("%s% d\n","I4 = ",(int)I4);
}
int main (int argc,PCHAR* argv)
{
int i;
for(i=1; i<=3; i+=1)
{
DoTest();
printf("%s\n","********");
}
Pause();
return 0;
}
and the output:
I1 = 0
I2 = 0
I3 = 0
I4 = 0
----------
I1 = 1
I2 = 2
I3 = 3
I4 = 1
********
I1 = 0
I2 = 0
I3 = 0
I4 = 1
----------
I1 = 1
I2 = 2
I3 = 3
I4 = 2
********
I1 = 0
I2 = 0
I3 = 0
I4 = 2
----------
I1 = 1
I2 = 2
I3 = 3
I4 = 3
********