Recent

Author Topic: [Answered] Explanation of an odd type-construct?!?!?  (Read 5593 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1083
    • http://www.cdbc.dk
[Answered] Explanation of an odd type-construct?!?!?
« on: September 27, 2011, 06:56:49 am »
Hi everybody.

I'm wondering a little about the following type-construct:

Code: [Select]
type
  ppsqlite3 = ^psqlite3;
  psqlite3 = ^_sqlite3;
  _sqlite3 = record end;
{code lifted from SQLite3 interface }

Is this "a pointer to a pointer to a structure containing no data-members" ????????????
or "a pointer to a unspecified pointer to an 4/8 byte memory block" ???????
or something completely different....

Please could someone explain this to me in details, as i'm puzzled????

TIA
Regards - Benny
« Last Edit: September 29, 2011, 12:43:08 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Explanation of an odd type-construct?!?!?
« Reply #1 on: September 27, 2011, 07:27:57 am »
It is an opaque pointer. You are not allowed to / you should not care about the internals and just pass the pointer to it around.

cdbc

  • Hero Member
  • *****
  • Posts: 1083
    • http://www.cdbc.dk
Re: Explanation of an odd type-construct?!?!?
« Reply #2 on: September 29, 2011, 12:42:11 am »
Thank you Vincent.

Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: [Answered] Explanation of an odd type-construct?!?!?
« Reply #3 on: September 29, 2011, 01:45:28 am »
It's a pointer to a pointer to a structure containing members that cannot be accessed like usual structures. It can mean that you should not change it by yourself or that the members have variable width.

Anyway, it's a strange way to define it, because they could have simply define "psqlite3 = pointer".
Conscience is the debugger of the mind

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: [Answered] Explanation of an odd type-construct?!?!?
« Reply #4 on: September 29, 2011, 07:45:02 am »
If you use psqlite3 = pointer, then it is assignment compatible with other pointers. Now the following won't compile in certain modes.
Code: [Select]
type
 psqlite3 = ^_sqlite3;
  _sqlite3 = record end;
 potherthings= ^_otherthings;
  _otherthings = record end;

var
  a : psqlite3;
  b: potherthings;
begin
  SomeSqliteProcedure(a); // works
  SomeSqliteProcedure(b); // error: wrong type passed
end;

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: [Answered] Explanation of an odd type-construct?!?!?
« Reply #5 on: September 29, 2011, 07:25:02 pm »
What about "psqlite3 = type pointer" ?
Conscience is the debugger of the mind

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: [Answered] Explanation of an odd type-construct?!?!?
« Reply #6 on: September 29, 2011, 08:00:37 pm »
Try for yourself :-)

 

TinyPortal © 2005-2018