ndarkness
ndarkness

Reputation: 1099

Why do I get expected expression before 'int16_t' error in C?

I am working with the function

int max30205_write_trip_low_thyst(float temperature)//, I2C &i2c_bus)
{
    max30205_raw_data raw;
    temperature /= MAX30205_CF_LSB;
    raw.swrd = int16_t(temperature); // here -> expected expression before 'int16_t'
    return max30205_write_reg16(raw.swrd, MAX30205_REG_THYST_LOW_TRIP);//, i2c_bus);
}

and when I try to compile I get the following error expected expression before 'int16_t'

Why is this?

looking the header file I see that

#define MAX30205_CF_LSB           (0.00390625F)

typedef union max30205_raw_data {
    struct {
        uint8_t lsb;
        uint8_t msb;
    };
    struct {
        uint16_t magnitude_bits:15;
        uint16_t sign_bit:1;
    };
    uint16_t uwrd;
    int16_t swrd;
} max30205_raw_data;

Upvotes: 1

Views: 2164

Answers (1)

Lundin
Lundin

Reputation: 215115

Because int16_t(temperature); is not valid C syntax. You need to do (int16_t)temperature.

Upvotes: 4

Related Questions