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

krycha88
Posts: 5417
Joined: Fri Nov 16, 2018 7:25 am

Post

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

Code: Select all

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/
User avatar
pzygmunt
Posts: 19340
Joined: Tue Jan 19, 2016 9:26 am
Location: Paczków

Post

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
Posts: 5417
Joined: Fri Nov 16, 2018 7:25 am

Post

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

Ale mam jeszcze jedną zagwostkę

Jak mam zdefiniowany konstruktor w taki sposób:

Code: Select all

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:

Code: Select all

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

Code: Select all

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
Posts: 5417
Joined: Fri Nov 16, 2018 7:25 am

Post

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

Return to “Arduino IDE”