Should'nt this compile?

Beta Testing discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Should'nt this compile?

#1 Post by JimKueneman » 28 Mar 2010 00:08

Code: Select all

program Buggs;

{ Declarations section }
const
  PACKET_STATE_14_STEP_SPEED = 0;
  PACKET_STATE_28_STEP_SPEED = 1;
  PACKET_STATE_128_STEP_SPEED = 2;

var
  i: Byte;
begin
  i := 0;
  case i of
    PACKET_STATE_14_STEP_SPEED:  <<< ERROR >>>>
      begin
      end;
    PACKET_STATE_28_STEP_SPEED:
      begin
      end;
    PACKET_STATE_128_STEP_SPEED:
      begin
      end;
  end;
      
end.
18 301 "PACKET_STATE_28_STEP_SPEED:"is not valid identifier Buggs.mpas
I would expect this to compile. Am I wrong?

Jim

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

Re: Should'nt this compile?

#2 Post by OT » 28 Mar 2010 00:15

Even in the previous version, I always found that a begin end; - pair with no statements between caused execution trouble although it complied without error. Try inserting a nop; in between and see what happens. (Of course in Turbo pascal or Delphi your code would compile and execute unmodified).

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: Should'nt this compile? [Solved. Read the help file!]

#3 Post by JimKueneman » 28 Mar 2010 03:45

Does not matter.

Mmmm... sometimes reading help files is useful...
case byte_variable of

byte_var1: opmode := 0; // this will be compiled correctly

byte_var2:
opmode := 1; // avoid this case, compiler will parse
// a variable followed by colon sign as label

byte_var3: // adding a comment solves the parsing problem
opmode := 2;
end;
I don't think in Delphi you can use a variable as a value though!

This compiles...

Code: Select all

program Buggs;

{ Declarations section }
const
  PACKET_STATE_14_STEP_SPEED = 0;
  PACKET_STATE_28_STEP_SPEED = 1;
  PACKET_STATE_128_STEP_SPEED = 2;

var
  i: Byte;
begin
  i := 0;
  case i of
    PACKET_STATE_14_STEP_SPEED:   //
      begin
      end;
    PACKET_STATE_28_STEP_SPEED:  //
      begin
      end;
    PACKET_STATE_128_STEP_SPEED:  //
      begin
      end;
  end;
     
end.

Jim

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

Re: Should'nt this compile?

#4 Post by OT » 28 Mar 2010 06:25

The following works for me even without space before and after the colon,in a larger program. I have a vague memory ver.2 needed that space, but then there is content between begin -end here.

Code: Select all

ModeBaudRSel          : begin
                          Txt1:=ModeBaudRSelTxt;
                          ActSel:=BottActionSetSel;
                          UnitSel:=UnitBitsPerSec;
                        end; //Comment

JimKueneman
Posts: 417
Joined: 10 Jan 2009 22:03

Re: Should'nt this compile?

#5 Post by JimKueneman » 28 Mar 2010 17:39

The following works for me even without space before and after the colon,in a larger program. I have a vague memory ver.2 needed that space, but then there is content between begin -end here.

Yes, as long as there is something after the colon it works. You can see in the editor the color of the identifier is a Label when it won't compile. If you type something besides a space past the colon it color changes to the normal code color and it compiles.

Not a big deal just something to remember that is different from Delphi.

Jim

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing”