NO

Author Topic: Neither branch of a conditional runs in an if (test) else  (Read 2423 times)

PabloMack

  • Guest
Neither branch of a conditional runs in an if (test) else
« on: April 18, 2020, 10:22:39 PM »
I am using version 9.0.0.9. I have a complicated program, but I reduced the program down to a small one that still shows the problem. In both programs, when a conditional should be TRUE, the first set of statements do not run, but neither do those after the else conditional that should run if the test would evaluate to FALSE. The function just goes straight to returning the value STL_Inc at the end of the function. I understand that the two values that are compared are hard-coded so the conditional should always be TRUE in my small example. But the statements after the test never run.

I have attached the simplified program as well as the project file so you can see the project settings.
« Last Edit: April 19, 2020, 01:49:28 PM by PabloMack »

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Neither branch of a conditional runs in an if (test) else
« Reply #1 on: April 20, 2020, 02:25:25 PM »
Hi,

Just tried your example as coded but added printf("%s\n","True"); and printf("%s","False"); into the appropriate test spots. Removed ..\lib\sys.lib because it does not exist.

Worked correctly and showed True in the posted example, Changed val to 5 recompiled and ran - it then showed False.
So in both cases the conditional if ran just fine.

Regards,

PabloMack

  • Guest
Re: Neither branch of a conditional runs in an if (test) else
« Reply #2 on: April 20, 2020, 09:51:56 PM »
I replicated the same thing you did. The TRUE is printed. But the debugger apparently can't step to that line. If I try to place a break at that printf, I get the warning that is in the popup from which I created a picture that is attached. The debugger disables the break and it never happens. Something is still wrong here. I guess it is not something wrong with execution but with the debugger. I did turn off optimization, so the code should still be there.
« Last Edit: April 20, 2020, 09:53:28 PM by PabloMack »

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Neither branch of a conditional runs in an if (test) else
« Reply #3 on: April 20, 2020, 11:05:19 PM »
Try putting your break here line 83 St = vrb_PutLrg(&Blk,Blk); then use F11 into the procedure.
OR
put it here 42 if (Sum == Val); then use F11

May not be exactly what you want but this works.

Rgds,

PabloMack

  • Guest
I ran into this same bug again. I am convinced now that it is a bug in the debugger and not the compiler. What I did was to build the same module using my trusty old Watcom compiler. I built, debugged and tested it. The Watcom debugger works and I can step through the code. The Pelles C compiler generates working code and the executable seems to behave correctly. But I can't step through the code that follows the if (exp && exp) which is the same problem I saw before. Below is a fragment of the code that will not accept break points after the if (exp && exp). I can break right at the if (condition) but not even one of the lines within the curly braces will accept a break, though there are many. Once I step beyond the if () line then the next thing I see is that the function has returned and I am no longer even inside that function any more.

    //Fount It?
    if ((Spc == Ctr->Spc) && (Pag == Adr))
     {
      register ATE *Ntr,*Ptr;      //Nxt,Prv Record Pointers
      ub Anc=ate_NxtR(Ctr);        //Might need New Beg

      //Only One Changes Nothing
      if (Atc->Cnt == 1)
        return Ctr;

      //Can Only Happen When Full
      if (Cur == Atc->End)
       {
        Atc->Beg = ate_NxtR(Ctr);
        Atc->End = Atc->Beg;
        return Ctr;
       }

      //Read Nxt & Prv
      Nxt=ate_NxtR(Ctr);
      Prv=ate_PrvR(Ctr);

      //Get Pointers to Nxt & Prv
      Ntr = &Atc->Ary[Nxt];
      Ptr = &Atc->Ary[Prv];

      //Remove Cur from Chain
      ate_NxtW(Ptr,Nxt);
      ate_PrvW(Ntr,Prv);

      //Place between End and its Prv
      Nxt = Atc->End;
      Ntr = &Atc->Ary[Nxt];
      Prv = ate_PrvR(Ntr);
      Ptr = &Atc->Ary[Prv];

      //Insert Cur
      ate_PrvW(Ntr,Cur);
      ate_NxtW(Ptr,Cur);
      ate_NxtW(Ctr,Nxt);
      ate_PrvW(Ctr,Prv);

      //New Beg
      if (Cur == Atc->Beg)
        Atc->Beg = Anc;

      //Success
      return Ctr;
     }
« Last Edit: April 27, 2020, 04:04:42 PM by PabloMack »

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Neither branch of a conditional runs in an if (test) else
« Reply #5 on: April 28, 2020, 12:11:37 PM »
Something is going on differently in your code that is for sure.  I tested in one of my larger programs and it worked fine, see attachment.  So it is definitely exceeding my limited knowledge, I do not normally use the debug mode.

Regards