Skip to content

Possible problem with signed/unsigned char #97

@lynxzp

Description

@lynxzp

When I moved excising project on Arduino Due, I got compiler warning

comparison (celsius < -55) is always false due to limited range of data type

1 Because char is unsigned by default on ArduinoDdue, forum discussion. Maybe char need replace with signed char?

2 But also I noticed that this signed value later convert in unsigned before sending on device. Don't know is it right or not.

void DallasTemperature::setHighAlarmTemp(const uint8_t* deviceAddress, char celsius){
    // make sure the alarm temperature is within the device's range
    if (celsius > 125) celsius = 125;
    else if (celsius < -55) celsius = -55;

    ScratchPad scratchPad;
    if (isConnected(deviceAddress, scratchPad)){
        scratchPad[HIGH_ALARM_TEMP] = (uint8_t)celsius;
        writeScratchPad(deviceAddress, scratchPad);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions