Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weird structure declaration method in C

Tags:

c

struct

This is from the header file for the library functions of CSR8670 Bluetooth chip

typedef struct TaskData { void (*handler)(Task, MessageId, Message); } TaskData;  

What kind of structure declaration is this? What are the member data for this structure?
Here is the full header file for context:

/* This file was automatically generated from syscalls.in 17.2 */

#ifndef __MESSAGE__H

#define __MESSAGE__H

#include <csrtypes.h>
/*! @file message_.h @brief Message types */
/*!
Message identifier type.
*/
typedef uint16 MessageId;
/*!
Message delay type.
*/
typedef uint32 Delay;
/*!
Message type.
*/
typedef const void *Message;
/*!
Task type.
*/
typedef struct TaskData *Task;
/*!
TaskData type.
*/
typedef struct TaskData { void (*handler)(Task, MessageId, Message); } TaskData;

#endif  

I am still not sure what *handler means. I have not been able to find any other references to handler in the other header file. If it's relevant, Task represents a sort of routine running on the firmware that accepts and processes the message that the firmware may receive from external sources (for example, a bluetooth device trying to connect to the CSR board).

like image 787
user13267 Avatar asked Apr 25 '26 09:04

user13267


1 Answers

handler is a pointer to a function that returns void and has parameters with types Task, MessageId, and Message in that order.

TaskData is a structure containing that one member.

It's probably used by some library function to call a function that the user of that library has to define. (These are known as callback functions and are idiomatic in C.)

like image 99
Bathsheba Avatar answered Apr 28 '26 08:04

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!