Jump to content

How would I port this code?


Recommended Posts

type

TDayTable = array[1..12] of Word;

 

const

{ True=Leapyear }

MonthDays: array [boolean] of TDayTable =

((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),

(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));

 

I get an error: ")" expected. It puts the cursur just after the first 31 on the first line of constants.

 

Thankes.

Link to post
Share on other sites

I solved this as follows:

 

const

LeapMonthDays: TDayTable = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

NormalMonthDays: TDayTable = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

MonthDays: array [boolean] of TDayTable = (NormalMonthDays, LeapMonthDays);

 

I'm not sure if there is a lesson to be learned here. I think it would be that complex constant arrays will have to be simplified first.

 

Thanks

Kevin

Link to post
Share on other sites

Delimiter for array constants is [], so

MonthDays: array [boolean] of TDayTable = 
 [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], 
  [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];

will work, the () was supported only for non-nested arrays (when the type is known).

For the next version I version I extended the compiler so it will accept them for nested arrays as well when the type is fully qualified (as in your case).

 

The reason behind using [] is to support array constants outside constant declarations, to initialize an array variable f.i, and also to allow type inference. The () constant array syntax is thus only supported for constant definitions, while [] is supported everywhere.

Link to post
Share on other sites

Eric,

 

Thanks for the reply. I am porting some code from the Lazarus library. I'd have to check if this is an issue unique to the FPC compiler, but I thought that the Delphi compiler used ()'s instead of []'s. Your explanation makes sense, but it is also nice if it works similar to other pascal compilers. Makes porting easier. So I am glad that you are supporting either syntax.

 

Kevin

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...