In particular, if I have the following type of function pointer:
typedef void (*callback_type) (intptr_t context, void* buffer, size_t count);
Can I safely and without "undefined behavior" do:
callback_type func_ptr = (callback_type)write; intptr_t context = fd; func_ptr(context, some_buffer, buffer_size);
?
Where write() is the system call (EDIT: has the signature ssize_t write(int fd, const void *buf, size_t count); therefore, it takes int as the first argument), and fd is the file descriptor int . I assume that the answer will be the same for C and C ++, so I mark both.
source share