Recent

Author Topic: Zero Sized Array at end of Records, can this test code be verified ?  (Read 10225 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 3656
  • Compiler Developer
Re: Zero Sized Array at end of Records, can this test code be verified ?
« Reply #30 on: December 06, 2021, 02:06:52 pm »
Or is this to have the memory footprint of a C-struct:

Code: C  [Select][+][-]
  1. struct SomeArray {
  2.     int Length;
  3.     int* Elements;
  4. };

Like Pascal strings/arrays?

No, it's to get the equivalent for the following C-struct:

Code: C  [Select][+][-]
  1. struct SomeArray {
  2.   int Length;
  3.   int Elements[];
  4. }

Which is different from the one you posted, because the elements of Elements directly follow SomeArray where as in your example the data of Elements might be anywhere. These kind of embedded arrays are rather common for example in the Windows API.

Playing with the Generic's sample that Pascal posted it compiles etc but it does not INLINE.

do it without generics and it does inline.

I did this on 3.0.4 fpc so I don't know if higher levels have fixed this ?

For now I will stick with non generics because I don't want the calls for the setter and getter...

That was indeed improved with 3.2.0 as that also introduced generic routines and for those I definitely wanted inlining so I had to rework the way this is handled inside the compiler a bit. The important point however is: The body of the generic needs to have been parsed before the call that is supposed to be inlined (which is consistent with non-generic code).

 

TinyPortal © 2005-2018