Recent

Author Topic: Constant arrays with record, basic declaration difficulties  (Read 1263 times)

process_1

  • Guest
Constant arrays with record, basic declaration difficulties
« on: August 05, 2020, 08:53:35 pm »
In Pascal we all know that with constant arrays with a record, we have to declare them as this, with identifier:

Code: Pascal  [Select][+][-]
  1. type
  2.   TPoint = record
  3.     X, Y: integer;
  4.   end;
  5.  
  6. const
  7.   Data: array [0..1] of TPoint = (
  8.     (X: 1; Y: 5),
  9.     (X: 3; Y: 6)
  10.     );
  11.  
  12.  

That is no problem with small amount of constants, but with large one it is. It is difficult to write it (unless write small utils to create such source) and not quite readable.

Is there a syntax, or a plan to make this much more simpler, similar as in C/C++ ?
« Last Edit: August 05, 2020, 09:03:19 pm by process_1 »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Constant arrays with record, basic declaration difficulties
« Reply #1 on: August 05, 2020, 10:03:47 pm »
Is there a syntax, or a plan to make this much more simpler, similar as in C/C++ ?

No and no.

(Though maybe the pure routines suggested by J. Gareth Moreton (basically an equivalent to C++'s constexpr) can be used for this)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Constant arrays with record, basic declaration difficulties
« Reply #2 on: August 05, 2020, 10:14:56 pm »
Hi!

The practice tells you, that even if you do it all manuel - the compiler helps you:

* to less elements: the compiler says "expected another xx ...."
* to much elements: the compiler complains that the array is not closed. The Cursor is placed at the last accepted element. So you can count how much to in crease the high  bound.

And to write a tool that formats you array is most times an easy job : 10 lines of code or less.

Winni

« Last Edit: August 05, 2020, 10:16:31 pm by winni »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Constant arrays with record, basic declaration difficulties
« Reply #3 on: August 05, 2020, 10:15:58 pm »
What do you mean "with large one"? What kind of data it is? Wouldn't be more handy to load it from file?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

process_1

  • Guest
Re: Constant arrays with record, basic declaration difficulties
« Reply #4 on: August 05, 2020, 10:50:56 pm »
What do you mean "with large one"? What kind of data it is? Wouldn't be more handy to load it from file?

I'm making some CPU emulators including abiliy to debug code, all from ground. In order to make it more efficient, I have to declare constant array with several elements, while the length of it is under 100 (for RISC). Among these elements related with the CPU instruction is the pointer to the execution function, thus it is not practiacal to rely on any external file.
« Last Edit: August 05, 2020, 11:05:48 pm by process_1 »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Constant arrays with record, basic declaration difficulties
« Reply #5 on: August 05, 2020, 10:52:16 pm »
Hi!

Something like "allowed audio suffixes" will be something like 15 or 20 - that can be done manual.

But with more it starts to get a pain.
Either you read  it from a file.
Or you write a little tool to format your ArrayOfTPoint (or whatever).

Winni

 

TinyPortal © 2005-2018