kohi
kohi copied to clipboard
Forward-declare platform_state structure instead of using void pointers.
Not really a bug, but a good point brought up by keldwikchaldain9545 on YouTube. Tracking this here so it doesn't get lost.
Quote from the comment post:
I know I'm years too late, but the platform_state could be defined in a way that I think would be a little better.
If you declare a struct with a typedef, you don't have to give it fields, you can leave it undefined, and you can then handle instances of that structure as long as you only do so behind a pointer. So you could do the following:
typedef struct platform_state_t *PlatformState;
And then from all your external code you handle a PlatformState which is a pointer to the platform state, and then inside your implementation you take that pointer and it's already the correct type. No need to do implicit casts with void *.
It's better to avoid typedefing pointers. Otherwise one may experience a lot of headaches with const
qualifier. For example in:
typedef struct platform_state_t *PlatformState;
const PlatformState platform_state;
The type of platform_state
is struct platform_state * const
, not const struct platform_state *
. The pointer itself is const, not the object it points two.
This was previously fixed in the 0.7.0 refactor. Closing this.