warning: 'sht3x' may be used uninitialized in this function [-Wmaybe-uninitialized]

krycha88
Posty: 5186
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

Postanowiłem pozbyć się ostrzeżeń kompilatora ale nie rozumiem co tutaj jest nie tak:

Kod: Zaznacz cały

C:/Users/kryst/Documents/PlatformIO/Projects/GUI-Generic/src/GUI-Generic.ino:291:60: warning: 'sht3x' may be used uninitialized in this function [-Wmaybe-uninitialized]
       Supla::GUI::addConditionsTurnOFF(SENSOR_SHT3x, sht3x);
miejsce występowania ostrzeżenia:
https://github.com/krycha88/GUI-Generic ... c.ino#L285

metoda addConditionsTurnOFF:
https://github.com/krycha88/GUI-Generic ... I.cpp#L362
https://gui-generic-builder.supla.io/
Awatar użytkownika
pzygmunt
Posty: 18278
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

https://github.com/krycha88/GUI-Generic ... c.ino#L271
shut3x nie jest zainicjowane. Teoretycznie jeśli nie wejdzie w żadnego case-a to będziesz miał tam randomowy wskaźnik na nieistniejącą instancję obiektu.
krycha88
Posty: 5186
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

dzięki, poprawiłem aby nie było takiej sytuacji :)

Ale mam jeszcze jedną zagwostkę

Jak mam zdefiniowany konstruktor w taki sposób:

Kod: Zaznacz cały

Percentage::Percentage(Supla::ChannelElement *src,
                      int16_t minValue,
                      int16_t maxValue,
                      bool useAlternativeMeasurement)
    : source(src),
      _minValue(minValue),
      _maxValue(maxValue),
      useAlternativeMeasurement(useAlternativeMeasurement),
      lastReadTime(0) {
}
to kompilacja się wywala:

Kod: Zaznacz cały

lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:37:26: error: 'Supla::Sensor::Percentage::source' will be initialized 
after [-Werror=reorder]
   Supla::ChannelElement *source;
                          ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:34:11: error:   'int16_t Supla::Sensor::Percentage::_minValue' [-Werror=reorder]
   int16_t _minValue;
           ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.cpp:21:1: error:   when initialized here [-Werror=reorder]
 Percentage::Percentage(Supla::ChannelElement *src,
 ^
In file included from lib/SuplaDeviceExtensions/src/supla/sensor/percentage.cpp:17:0:
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:35:11: error: 'Supla::Sensor::Percentage::_maxValue' will be initialized after [-Werror=reorder]
   int16_t _maxValue;
           ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:33:8: error:   'bool Supla::Sensor::Percentage::useAlternativeMeasurement' [-Werror=reorder]
   bool useAlternativeMeasurement;
        ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.cpp:21:1: error:   when initialized here [-Werror=reorder]
 Percentage::Percentage(Supla::ChannelElement *src,
 ^
In file included from lib/SuplaDeviceExtensions/src/supla/sensor/percentage.cpp:17:0:
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:33:8: error: 'Supla::Sensor::Percentage::useAlternativeMeasurement' will be initialized after [-Werror=reorder]
   bool useAlternativeMeasurement;
        ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.h:32:17: error:   'long unsigned int Supla::Sensor::Percentage::lastReadTime' [-Werror=reorder]
   unsigned long lastReadTime;
                 ^
lib/SuplaDeviceExtensions/src/supla/sensor/percentage.cpp:21:1: error:   when initialized here [-Werror=reorder]
 Percentage::Percentage(Supla::ChannelElement *src,
 ^
cc1plus.exe: some warnings being treated as errors

A jak zapiszę konstruktor w taki sposób to jest już dobrze :D

Kod: Zaznacz cały

Percentage::Percentage(Supla::ChannelElement *src,
                       int16_t minValue,
                       int16_t maxValue,
                       bool useAlternativeMeasurement) {
  source = src;
  _minValue = minValue;
  _maxValue = maxValue;
  useAlternativeMeasurement = useAlternativeMeasurement;
  lastReadTime = 0;
}
percentage.h
https://github.com/krycha88/GUI-Generic ... rcentage.h

percentage.cpp
https://github.com/krycha88/GUI-Generic ... entage.cpp
https://gui-generic-builder.supla.io/
krycha88
Posty: 5186
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

dobra już wiem, kolejność zmiennych ma znaczenie :D
https://gui-generic-builder.supla.io/
ODPOWIEDZ

Wróć do „Arduino IDE”