I have the following code so as to be able to access numerous fields in array of structs (I've reduced it to two for simplicity). What is the correct incantation for the final pointer calculation
*(ptr + offset) = data;
because I always get :
error: incompatible types when assigning to type ‘struct osc_in_data’ from type ‘int32_t’ {aka ‘int’}
#define NumHarmonics 10
int32_t data1;
int32_t data2;
struct osc_in_data
{
int32_t LevelAttackRate;
int64_t LevelPeakLevel;
int32_t LevelDecayRate;
} OscControl[NumHarmonics];
void SetADSRvalues(int32_t offset, int32_t data)
{
int32_t harmonic;
struct osc_in_data *ptr;
for (harmonic = 0; harmonic < NumHarmonics; harmonic++)
{
ptr = &OscControl[harmonic];
*(ptr + offset) = data;
}
}
SetADSRvalues(offsetof(struct osc_in_data, LevelAttackRate), data1)
SetADSRvalues(offsetof(struct osc_in_data, LevelDecayRate), data2)