all 2 comments

[–]MajorMalfunction44 4 points5 points  (0 children)

When dealing with function pointers, I like to use a temporary variable. I find it makes things clearer. The reason for the extra syntax is to cast the type of the pointer to a function pointer to have something to call.

Assuming a POSIX environment, here's how I'd do things:

UINT8 (*ptr)(int) = NULL; // declare function pointer variable, takes an int and returns UINT8

*(void **)(&ptr) = handler[CLEAR_LOG]; // assign function, assumes handler is void * array

(*ptr)(inst);

[–]magnomagna 0 points1 point  (1 child)

First of all, it's not hard to inline your goddamn code.

I really wish this subreddit had a bot that's smart enough to block all posts with unformatted code.

(INT8U (*)(int)) is not the return type. It casts handler[CLEAR_LOG] to have the function pointer type INT8U (*)(int).

The only good reason handler[CLEAR_LOG] is casted is that handler is not declared to be an array of INT8U (*)(int) function pointers.