Recent

Author Topic: [Solved] Not enough error detection for array-char type  (Read 518 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
[Solved] Not enough error detection for array-char type
« on: March 13, 2023, 07:17:47 pm »
Code: Pascal  [Select][+][-]
  1. program tst_arr;
  2.  
  3. type
  4.   TElem = (e1, e2, e3);
  5.   TElemStr = array[TElem] of char;
  6.  
  7. var
  8.   elStr: TElemStr = '12';
  9.  
  10. begin
  11. end.
  12.  
This is compiled by FPC. Lazarus 2.3.0 (rev main-2_3-1386-g23b2324f9f) FPC 3.2.3 x86_64-linux-gtk2.
If elStr has 4 chars - error is detected, if 2 - not detected. 2 items is error - elStr must have 3 chars.
« Last Edit: March 14, 2023, 07:23:28 am by AlexTP »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Not enough error detection for array-char type
« Reply #1 on: March 13, 2023, 08:55:31 pm »
Using '12' is in fact a shortcut for ('1','2').
If you change the code:
Code: Pascal  [Select][+][-]
  1. var
  2.   elStr: TElemStr = ('1','2');
you get an error:
Code: Pascal  [Select][+][-]
  1. project1.lpr(8,29) Error: Expected another 1 array elements
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/

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Not enough error detection for array-char type
« Reply #2 on: March 13, 2023, 11:16:37 pm »
If elStr has 4 chars - error is detected, if 2 - not detected. 2 items is error - elStr must have 3 chars.

A static array of Char can take at most the amount of characters that the index specifies, but it can have less (the remainder will be filled with #0).

 

TinyPortal © 2005-2018