April 25, 2024, 07:34:20 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Brace (curly bracket) problem

Started by John Syl., March 28, 2007, 11:02:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Syl.

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
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

Ionic Wind Support Team

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.
Ionic Wind Support Team

John Syl.

Thanks for a quick reply on that. 
John
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)