Callback without function pointer

Usually they say that callbacks are implemented with function pointers. When I check the source code of PortAudio, I see that the callback function is declared as a regular function (and not the f pointer). Is this normal / legal / appropriate?

typedef int PaStreamCallback(
const void *input, void *output,
unsigned long frameCount,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );
+3
source share
1 answer

This is normal as long as the parameter is used as PaStreamCallback*(which is a function pointer), e.g.

PaError Pa_OpenStream   (
        PaStream **      stream,
        const PaStreamParameters *      inputParameters,
        const PaStreamParameters *      outputParameters,
        double      sampleRate,
        unsigned long   framesPerBuffer,
        PaStreamFlags   streamFlags,
        PaStreamCallback *      streamCallback,   // <---
        void *      userData     
    ) 
+4
source

Source: https://habr.com/ru/post/1759475/


All Articles