I'm learning how to program for ALSA in Linux and there's a piece of code like this:
snd_pcm_t * _soundDevice;
bool Init(const char *name)
{
int i;
int err;
snd_pcm_hw_params_t *hw_params;
if( name == NULL )
{
// Try to open the default device
err = snd_pcm_open( &_soundDevice, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0 );
}
As you can see, it first creates the pointer to the struct snd_pmc_t
and name it _soundDevice
. Other parts of the code, however, use only the first pointer:
if ((err = snd_pcm_hw_params_any (_soundDevice, hw_params)) < 0)
I understand that a pointer to a struct is helpful to pass as an argument because passing the entire struct as a copy would be bad, and I also understand that this function modifies the content of the struct that the pointer points to, but why should somebody need a pointer to a pointer to a struct?