Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[remove Compiler Warning]: caused by unused Variable in SHTSensor.h #16

Closed
hasenradball opened this issue Jun 5, 2021 · 11 comments · Fixed by #17
Closed

[remove Compiler Warning]: caused by unused Variable in SHTSensor.h #16

hasenradball opened this issue Jun 5, 2021 · 11 comments · Fixed by #17
Assignees
Labels

Comments

@hasenradball
Copy link

Hi,

I have a proposal to remove a silly Compiler warning in line 160 of SHTSensor.h:

see here:

          virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) {
                 return false;
          }

causes a silly compiler warning which can be prevented like:

          virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) {
                (void) newAccuracy;
                return false;
          }
@winkj
Copy link
Member

winkj commented Jun 7, 2021

Looks good, thanks for reporting this. While harmless, libraries should not generate warnings. Alternatively, we could used __attribute__((unused))

@winkj winkj self-assigned this Jun 7, 2021
@winkj winkj added the bug label Jun 7, 2021
@hasenradball
Copy link
Author

Hi thanks for watching 😀.
How will it look like with the attribute((unused))?

@winkj
Copy link
Member

winkj commented Jun 7, 2021

It would look like this:

virtual bool setAccuracy(__attribute__((unused)) SHTSensor::SHTAccuracy newAccuracy) {
    return false;
}

I've briefly tried to recreate the compiler warning in Arduino IDE, but failed to do so. Could you share the setup you used to get this warning so we can verify that it's fixed? Thanks

@winkj
Copy link
Member

winkj commented Jun 7, 2021

Alternatively, we can simply omit the parameter name:

virtual bool setAccuracy(SHTSensor::SHTAccuracy /* newAccuracy* /) {
    return false;
}

This should fix it too

@hasenradball
Copy link
Author

Hi Johannes,

I use Platform IO where I am able to set the Warning level in GCC compiler like that:

; Debug Flag Serial or Serial1
build_flags =
    -Wall
    -Wextra

The sesult is like that:

In file included from D:\PIO_libs\cSensorSHT31/cSensor_SHT31.h:7,
                 from D:\PIO_libs\cSensorSHT31\cSensor_SHT31.cpp:8:
.pio\libdeps\esp12e\arduino-sht/SHTSensor.h: In member function 'virtual bool SHTSensorDriver::setAccuracy(SHTSensor::SHTAccuracy)':
.pio\libdeps\esp12e\arduino-sht/SHTSensor.h:160:51: warning: unused parameter 'newAccuracy' [-Wunused-parameter]
  160 |   virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) {

@hasenradball
Copy link
Author

I tried to set the warning level in Arduino IDE, but I didn't found where.

@hasenradball
Copy link
Author

virtual bool setAccuracy(__attribute__((unused)) SHTSensor::SHTAccuracy newAccuracy) {
    return false;
  }

works also fine
:-)

@hasenradball
Copy link
Author

Hi Johannes,
kann ich noch eine Frage stellen?
Ich habe einen ESP8266 mit einem SHT31 Sensor.

Ich nutze folgendes Setup:

namespace SHT {
  class Sensor_SHT31 {
    private:
      uint8_t _sda_pin, _scl_pin;
      SHTSensor sht = SHTSensor(SHTSensor::SHT3X);

    public:
      bool sensor_available;
      bool send_data2DB;
      struct Messung {
        time_t zeit;
        float Messwert1;
        float Messwert2;
        float Messwert3;
        float Messwert4;
      } Data;
      explicit Sensor_SHT31(uint8_t sda_pin, uint8_t scl_pin);
      bool setup(void);
      void measure();
  };
}
bool SHT::Sensor_SHT31::setup() {
  // SDA, SCL
  Wire.begin(_sda_pin, _scl_pin);
  delay(100);
  sensor_available = sht.init();
  DBG__PRINT(">>> SHT31D-Sensor - init(): ", sensor_available, "\n\n");
  // only supported by SHT3x
  sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM);
  return sensor_available;

Das sht.init() liefert mir einen true Wert obwohl kein Sensor angeschlossen ist.

Ist das normal?

@winkj
Copy link
Member

winkj commented Jun 8, 2021

@hasenradball das ist konsistent mit dem Code wenn ein Sensor-Typ angegeben wird, aber nicht unbedingt sinnvoll. Werde das auch gleich anschauen

@winkj
Copy link
Member

winkj commented Jun 8, 2021

@hasenradball both issues are addressed in pull request #17

@winkj winkj linked a pull request Jun 8, 2021 that will close this issue
@hasenradball
Copy link
Author

Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants