lundi 5 mars 2018

C expression must be a modifiable lvalue (Why am i getting on this expression)

I have this expression with ?: operator:

(adc.Voltage1[Counter.ADC_ConversionCount] = ADC_readResult(Handler.myAdc, ADC_ResultNumber_1))  > 10 ? Counter.WriteOut = 1 : Counter.WriteOut = 0;

And the same expression with if-else:

if((adc.Voltage1[Counter.ADC_ConversionCount] = ADC_readResult(Handler.myAdc, ADC_ResultNumber_1)) > 10 ){
    Counter.WriteOut = 1;
}else{
    Counter.WriteOut = 0;
}

Why am I getting "expression must be a modifiable lvalue" error in the first case?

The ADC_readResult function return type is uint_least16_t. Here is the Counter struct definition and the ADC struct definition:

typedef struct __COUNTERS__ {
    uint16_t WriteOut;
    uint16_t ADC_ConversionCount;
    uint16_t ADC_CycleCount;
    uint8_t LimitADCReached1;
    uint8_t LimitADCReached2;
    uint8_t LimitADCReached3;
    uint8_t LimitADCReached4;
    uint8_t LimitADCReached5;
} COUNTERS;

typedef struct __ADC_VOLTAGES__ {
    uint16_t Voltage1[ADC_VAL];
    uint16_t Voltage2[ADC_VAL];
    uint16_t Voltage3[ADC_VAL];
    uint16_t Voltage4[ADC_VAL];
    uint16_t Voltage5[ADC_VAL];

} ADC;

Aucun commentaire:

Enregistrer un commentaire