3

It is usually said callbacks are implemented with function pointers. When I check PortAudio's source code, I see that callback function is declared as an ordinary function (not a f. pointer). Is it normal/legal/advisable?

typedef int PaStreamCallback(
const void *input, void *output,
unsigned long frameCount,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );

1 Answer 1

4

It is fine as long as the parameter is used as PaStreamCallback* (which is a pointer to a function), like

PaError Pa_OpenStream   (
        PaStream **      stream,
        const PaStreamParameters *      inputParameters,
        const PaStreamParameters *      outputParameters,
        double      sampleRate,
        unsigned long   framesPerBuffer,
        PaStreamFlags   streamFlags,
        PaStreamCallback *      streamCallback,   // <---
        void *      userData     
    ) 
Sign up to request clarification or add additional context in comments.

2 Comments

ok, thanks. by the way, the functions are passed to Pa_OpenStream with their names only, however logically must be passed with addressof operator, but omitting & is a shortcut, right?
@paul if foo is a function, foo and &foo are equivalent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.