I have searched and found a lot of similar questions (with undoubtly good answers) but I haven't found one that I understand completely. I have found a solution that does work and I am really just trying to understand what I do wrong in the first example...
I wrote a function that calculates pitch/roll from raw accelerometer values with declaration:
uint8_t calcPitchRoll (imu_t * imu, float * pitch, float * roll);
The calling function looks like (line numbers for reference):
518 float * pRollValue, * pPitchValue; // prepare pointers to floats to store results
519 *pRollValue = 0; // initialize variables
520 *pPitchValue = 0; // initialize variables
521 calcPitchRoll (imu, pPitchValue, pRollValue);
However, that results in the compiler warnings:
main.c:519:25: warning: 'pRollValue' may be used uninitialized in this function
main.c:521:26: warning: 'pPitchValue' may be used uninitialized in this function
The following however does work:
float PitchValue, RollValue = 0;
float * pRollValue = &RollValue;
float * pPitchValue = &PitchValue;
calcPitchRoll (imu, pPitchValue, pRollValue);
To me, both examples seem to have the same "state" when calling the calcPitchRoll function, but the compiler disagrees.
What I (think I) understood is that *pRollValue = 0 writes that value to the variable, so I'd think at that point the variable has space allocated ànd a value. Is that an incorrect understanding?