IonicWind Software

Aurora Compiler => General Discussion => Topic started by: John Syl. on March 28, 2007, 11:02:49 AM

Title: Brace (curly bracket) problem
Post by: John Syl. on March 28, 2007, 11:02:49 AM
Forgive me if this is a known problem I've searched but I can't find anything about it.

the following code simulates a problem that I have experienced, mainly a missing closing brace.  The code is purely to demonstrate this problem

The code below has a brace remarked out, the code compiles and runs fine but the results are not as expected.

with the brace inserted a message box should be displayed giving the caption as "Error in Data", however it shows the box with the caption
,"Box Should never show!!".

I suspect it has something to do with the do{}until(), as without this, the missing brace flags a compile error.


Sub main()
{
int n;
n=Func();
return;
}

Sub Func(),int
{
int err;
err=0;
do
{
err=1;
if (err)
{
if(err=1)
{
s="Incorrect Data!";
}
else
{
s="Invalid data!";
// }
messagebox(0,s,"Error in Data",IDOK);
}
else
{
err=1;
messagebox(0,s,"Box Should never show!!",IDOK);
}
}
until(err<>0);
return err;
}


regards John
Title: Re: Brace (curly bracket) problem
Post by: Ionic Wind Support Team on March 28, 2007, 11:11:08 AM
I will look into it.  Basically you are throwing off the context of the compiler.  With the missing brace the compiler sees this:


Sub Func(),int
{
int err;
err=0;
do
{
err=1;
if (err)
{
if(err=1)
{
s="Incorrect Data!";
}
else
{
s="Invalid data!";
// }
messagebox(0,s,"Error in Data",IDOK);
}
else
{
err=1;
messagebox(0,s,"Box Should never show!!",IDOK);
}
}
until(err<>0);
return err;
}


Which is two else's after an if.  The second else pops the context stack removing the first 'if' context so it is as if it never existed in the first place, and you don't get an error.

Paul.
Title: Re: Brace (curly bracket) problem
Post by: John Syl. on March 28, 2007, 12:40:36 PM
Thanks for a quick reply on that. 
John