Recent

Author Topic: array of array of type?  (Read 1187 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5197
  • Compiler Developer
Re: array of array of type?
« Reply #15 on: June 02, 2023, 10:31:57 pm »
I thought the idea of "array of ..." parameters was that I can pass any array to them. What I'm doing wrong?

An open array is always one dimensional. In theory a static array could be passed to an open array parameter of the same element type, but the compiler simply doesn't allow it to pass multi dimensional static arrays to an open array parameter.

Code: Pascal  [Select][+][-]
  1.  FillDWord(A,SizeOF(A) DIV 4, 1);
  2.  

Really?
Code: Pascal  [Select][+][-]
  1. program Size;
  2.  
  3. var a: array [1..3, 1..3] of integer;
  4.  
  5. begin
  6.    WriteLn('FullLength(a)   = ', Length(a)*Length(a[1]));
  7.    WriteLn('SizeOf(a)       = ', SizeOf(a));
  8.    WriteLn('SizeOf(integer) = ', SizeOf(integer));
  9.    WriteLn('SizeOf(a) div 4 = ', SizeOf(a) div 4);
  10.    WriteLn('whoops!');
  11. end.
  12.  

Code: [Select]
FullLength(a)   = 9
SizeOf(a)       = 18
SizeOf(integer) = 2
SizeOf(a) div 4 = 4
whoops!

I think we can do this all day!
 :D

Let's rather stop here.

In modes ObjFPC and Delphi the size of Integer is 4, not 2. Your original example used $mode ObjFPC, thus the 4 from jamie is correct. And even in modes with SizeOf(Integer) = 2 the FillDWord would need a div 4, because FillDWord always works on 4 Byte values. For 2 Byte values you'd need to use FillWord (note the missing D).

jamie

  • Hero Member
  • *****
  • Posts: 5675
Re: array of array of type?
« Reply #16 on: June 03, 2023, 04:42:22 pm »
Yeah, but I did make a mistake but since he didn't want to talk about it anymore I didn't correct it.

 He presented an odd number of bytes which leads me to believe he just maybe trolling a abit! :o

 it should of been.

 FillDWord(A, (SizeOF(A) Div 4)+(Sizeof(A) Mod 4),1);

That accounts for the odd number of bytes that get lost at the end.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018