Recent

Author Topic: Pointer to array questions  (Read 3755 times)

cdbc

  • Hero Member
  • *****
  • Posts: 2460
    • http://www.cdbc.dk
Re: Pointer to array questions
« Reply #15 on: August 04, 2025, 11:40:37 am »
Hi Peter
If you really want your head to spin, have a look inside 'LazUtf8' unit and see what can be done with string - pointer Shenanigans  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

PeterHu

  • Jr. Member
  • **
  • Posts: 52
Re: Pointer to array questions
« Reply #16 on: August 04, 2025, 12:46:28 pm »
Hi Peter
If you really want your head to spin, have a look inside 'LazUtf8' unit and see what can be done with string - pointer Shenanigans  :D
Regards Benny

I am studying  :P

PascalDragon

  • Hero Member
  • *****
  • Posts: 6184
  • Compiler Developer
Re: Pointer to array questions
« Reply #17 on: August 05, 2025, 10:01:11 pm »
Your answer contains no information about a pointer to a dynamic array variable being different from a pointer to the first element.
What I meant to explain is that whatever the array type, when you need a pointer to its content, take the pointer to the first element. @a[Low(a)].
The low() is only necessary for fixed arrays that do not start from zero.  Dynamic arrays always start at a[0];
But you can use Low() for both types.

Again, your answer didn't explain why the pointer to dynamic array wasn't assignable to the PByte variable in PeterHu's original example, only how to retrieve a pointer to the first element.

 

TinyPortal © 2005-2018