Recent

Author Topic: unit ctypes;  (Read 372 times)

beria2

  • New Member
  • *
  • Posts: 20
unit ctypes;
« on: November 19, 2025, 05:01:21 am »
Please add the types needed for use in C libraries " puint8_t = ^uint8_t;
  uint8_t = byte;
  puint16_t = ^uint16_t;
  uint16_t = word;
  puint32_t = ^uint32_t;
  uint32_t = cardinal;
  puint64_t = ^  uint64_t;
  uint64_t = uint64;"

Khrys

  • Sr. Member
  • ****
  • Posts: 367
Re: unit ctypes;
« Reply #1 on: November 19, 2025, 06:51:11 am »
These types from  stdint.h  already exist, just without the  _t  suffix (e.g.  uint8_t = cuint8).
It's a bit inconsistent that  csize_t  does include the suffix while the others do not, though...

I'd also argue that  void*  is missing and should be added (perhaps as  pcvoid?)

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: unit ctypes;
« Reply #2 on: November 19, 2025, 07:18:19 am »
@Beria

I usually have included a macro for that to ease translating from C(++), but indeed they are already there under a  _t less name with the same meaning.
OTOH there are * a lot * more places in the  rtl where type aliases are defined or even redefined, so it is not an unreasonable request.

Actually, I support that, as long as you understand that they are already there under a different name.

@Khrys
void* or void * is a bit difficult to have a straight type translation because it is opaque by nature.
E.g. It can mean just an opaque pointer type or procedure. Quite different beasts. There is an alias for the first in system: POpaqueData and TOpaqueData. POpaqueData is a data, function or procedure  pointer to be explicitly defined, something that can only be done in C by using a macro or a cast, e.g:
Code: C  [Select][+][-]
  1. void (*callback)(int);
  2. void* p = (void*)callback;
  3. void* go_write_hello();
Pascal's type safety requires that the function/procedure ( pointer ) is of a known type.
Code: Pascal  [Select][+][-]
  1. type
  2.   PProcInt = ^TProcInt;
  3.   TProcInt = procedure(i: Integer);
  4.   PFuncInt = ^TFuncInt;
  5.   TFuncInt = function(i: Integer): Integer;
Where you can take the typed pointer for callbacks in a type safe way.
Of course, if typed pointers are on you can use @ instead of P.

 
« Last Edit: November 19, 2025, 07:53:16 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

beria2

  • New Member
  • *
  • Posts: 20
Re: unit ctypes;
« Reply #3 on: November 19, 2025, 08:42:41 am »
These types from  stdint.h  already exist, just without the  _t  suffix (e.g.  uint8_t = cuint8).
It's a bit inconsistent that  csize_t  does include the suffix while the others do not, though...



I know that there are such types there.... And it's also very easy to identify them with a suffix. I just think they were missed when ctypes were written, although in most of the C libraries that I use, it's just the types with the suffix.  And it's a very small change, but a useful one.

ps: I would still like a conditional compilation flag for the ILP64 model. ;-) It's also a simple thing to redefine multiple types in ctypes. It's an exotic thing, but I once came across something like this in C code...
« Last Edit: November 19, 2025, 08:54:48 am by beria2 »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12571
  • FPC developer.
Re: unit ctypes;
« Reply #4 on: November 19, 2025, 09:25:51 am »
These types from  stdint.h  already exist, just without the  _t  suffix (e.g.  uint8_t = cuint8).
It's a bit inconsistent that  csize_t  does include the suffix while the others do not, though...

ctypes is mostly pre C99. The types also exist without _t and are in system. I assume size_t solved some problem and was therefore used earlier in the BSD and Linux headers of the time.

Quote
I'd also argue that  void*  is missing and should be added (perhaps as  pcvoid?)

IIRC I mostly put types there that varied, and there is to my knowledge no place where it is not "pointer" ? 

ILP64 can be done, if such target is shown to work. Otherwise there is no way to activate the conditional, since units can only be compiled with one choice, and deviating from the OS settings will cause the OS RTL to fail to compile.

 

TinyPortal © 2005-2018