In most of SDL headers, opaque structs use the following kind of typedef:
typedef struct SDL_Thing SDL_Thing;
As such, when writing C code, the following variable declaration:
Is resolved by the compiler into:
Which causes a compilation failure, as struct SDL_Thing is an opaque struct with unknown size. Hence, to declare a pointer variable, the programmer must explicitly declare the variable as a pointer:
However, for whatever reason, SDL_net does things differently, and uses the following kind of typedef:
typedef struct _Thing *Thing;
As such, when writing C code, the following variable declaration:
Is resolved by the compiler into:
Which compiles fine, as this creates a pointer variable - unbeknown to the programmer (unless they actually look at the typedef).
So now, my question: how should we handle this in sdl2_net.pas in terms of type naming?
-
Keep the API similar to other units: make the TThing unavailable, and only use PThing everywhere. This makes it clear that PThing is a pointer to some data the programmer isn't meant to touch.
-
Keep the API close to the original C headers, and use TThing. This obscures the information that TThing is a pointer.
In most of SDL headers, opaque structs use the following kind of typedef:
As such, when writing C code, the following variable declaration:
Is resolved by the compiler into:
Which causes a compilation failure, as
struct SDL_Thingis an opaque struct with unknown size. Hence, to declare a pointer variable, the programmer must explicitly declare the variable as a pointer:However, for whatever reason, SDL_net does things differently, and uses the following kind of typedef:
As such, when writing C code, the following variable declaration:
Is resolved by the compiler into:
Which compiles fine, as this creates a pointer variable - unbeknown to the programmer (unless they actually look at the typedef).
So now, my question: how should we handle this in
sdl2_net.pasin terms of type naming?Keep the API similar to other units: make the
TThingunavailable, and only usePThingeverywhere. This makes it clear thatPThingis a pointer to some data the programmer isn't meant to touch.Keep the API close to the original C headers, and use
TThing. This obscures the information thatTThingis a pointer.