2

I am wondering how the RecieveInit function takes the CMD_GetChar function as an argument with no parameters. From what I understand, the ReceiveInit takes an rxChar argument which is a pointer to a uint8_t. It is then cast as a pointer to a void object (*RxCb), where CMD_GetChar takes a pointer to a uint8_t.

void CMD_Init(void)
{
  ReceiveInit( CMD_GetChar );
}

void ReceiveInit(  void (*RxCb)(uint8_t *rxChar) )
{
}

static void CMD_GetChar( uint8_t* rxChar)
{
}

How is CMD_GetChar being computed within ReceiveInit when it doesn't even have an argument to parse?

jabroni
  • 167
  • 16
  • 1
    The argument isn't needed until the function is actually called. – Alexander Sep 16 '22 at 05:38
  • Your understanding is incorrect. `ReceiveInit` takes a pointer to function as its sole argument. That function takes a pointer to a `uint_8_t` as its argument, and returns `void`. So `CMD_GetChar` qualifies, and a pointer to it can be passed to `ReceiveInit`. – Tom Karzes Sep 16 '22 at 05:47
  • Does this answer your question? [Is void \*function() a pointer to function or a function returning a void\*?](https://stackoverflow.com/questions/58500806/is-void-function-a-pointer-to-function-or-a-function-returning-a-void) – the busybee Sep 16 '22 at 06:30

0 Answers0