Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-03

Why isn’t SizeOf() allowed in generic arrays?

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J.-c. Chu

Hi,

Could somebody explain why SizeOf() cannot be used in the definition of generic arrays? I know this is a current limitation of Delphi, but will it be possible to have this feature in Free Pascal first?

Best Regards, J.-c. Chu
Sven Barth
to J.-c. Chu
J.-c. Chu wrote 6 lines
Hi, Could somebody explain why SizeOf() cannot be used in the definition of generic arrays? I know this is a current limitation of Delphi, but will it be possible to have this feature in Free Pascal first?

Can you give a concrete example what you want to achieve, please?

Regards,
Sven

J.-c. Chu
to Sven Barth

type TBytesOverlay<T> = array [0..SizeOf(T) - 1] of Byte

Sven Barth wrote 15 lines
Am 29.03.2012 10:14, schrieb J.-c. Chu: > Hi, > > Could somebody explain why SizeOf() cannot be used in the definition of > generic arrays? I know this is a current limitation of Delphi, but will > it be possible to have this feature in Free Pascal first? > Can you give a concrete example what you want to achieve, please? Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Best Regards, J.-c. Chu
Sven Barth
to J.-c. Chu
J.-c. Chu wrote
type TBytesOverlay<T> = array [0..SizeOf(T) - 1] of Byte

As the following does work:

type
   TBytesOverlayLongint = array[0..SizeOf(LongInt) - 1] of Byte;

Your code should work as well, as e.g. TBytesOverlay<LongInt> should result in the above code. So please report this as a bug.

Regards,
Sven