I am using another programmer's component which demands a struct. the component is being updated once in a while and I want to validate there are no field I missing when I fill it up. I was thinking about it that way:
typedef struct //this is from the component's lib
{
float FrequencyMax;
float FrequencyAvg;
float PwrTotal;
float Vgrid;
float IappTot;
float IapparentMax;
float CurrentPhi;
}XApcInputs;
XApcInputs APC_input;
Apc_InterfaceIterInitStruct(&APC_input); //init struct
Apc_InterfaceIterArrangeStruct(&APC_input); //arrange with real values
if(Apc_InterfaceIterValidStruct(&APC_input)) //validation
APC_MainIter(&APC_input); //using component
how can I run over all addresses (when I know they are all float) inside the array by the size. Ive tried this:
void Apc_InterfaceIterInitStruct(XApcInputs *APC_input)
{
float* FirstAddres = APC_input;
float* LastAddres = APC_input+sizeof(XApcInputs)/sizeof(float);
while((FirstAddres++)!=LastAddres)
{
*FirstAddres = MAX_FLOAT;
}
}
bool Apc_InterfaceIterValidStruct(XApcInputs *APC_input)
{
float* FirstAddres = APC_input;
float* LastAddres = APC_input+sizeof(XApcInputs)/sizeof(float);
while((FirstAddres++)!=LastAddres)
{
if(*FirstAddres == MAX_FLOAT)
return false;
}
return true;
}
what do I miss? I still trying to practice and learn how to work with pointers