1.8.19 maybe found a bug

hi everybody,
maybe i've found a bug in 1.18.9. Feel free to report.

so long
please, have an eye on #4.
uebergebeArray.ino (6.7 KB)

Maybe you should tell us what the possible bug is that you have found.

And the below is wrong if you're using an 8-bit microcontroller.

const int BITRATE = 115200;                                          // Übertragungsrate MCU -> serieller Monitor (sM)

Note: I assume that you're talking about 1.8.19, not 1.18.9.

PS
It's a lot easier for people if you place your code in a post (using code tags) instead of attaching it.

Your sketch

/*#############################  #####          AUTOR: DG
  #############################  #######
  ###                     ###  ###   ###          SKETCHNAME: uebergebeArray
  ###                   ###  ###                  VERSION: 0.00.1
  ###                 ###  ###                    LETZTE AKTUALISIERUNG: 2022-06-13
  ###               ###  ###
  ###             ###  ###                        ZWECK:
  ###           ###  ###       #########
  ###         ###  ###         #########
  ###       ###  ###                 ###          BIBLIOTHEK:
  ###     ###  ###                   ###
  ###   ###  ###                     ###          BOARD-SUPPORT:
  #######  #############################
  #####  ###############################          GERÄTE-SUPPORT:
  /*====================================================================================================================+
  |                                         >>>   P R Ä P R O Z E S S O R   <<<                                         |
  +====================================================================================================================*/
#include <OneWire.h>                                                 // Initialisierung von 1-Kabel-Geräten
#include <DallasTemperature.h>                                       // Handling der Maxim/Dallas-1-Kabel-Geräte

/*====================================================================================================================+
  |                                        >>>   D E K L A R A T I O N E N   <<<                                        |
  +====================================================================================================================*/
const int BITRATE = 115200;                                          // Übertragungsrate MCU -> serieller Monitor (sM)
const byte PIN_ONEWIRE_BUS = 4;                                      // GPIO Datenbus

//const byte macAddr[]  = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x6C, 0x5C, 0x8B};
//const byte macAddr2[] = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x59, 0x03, 0xC3};

byte *retarray;
byte *ret2array;

/*====================================================================================================================+
  |                                      >>>   I N I T I A L I S I E R U N G   <<<                                      |
  +====================================================================================================================*/
OneWire oneWireBus(PIN_ONEWIRE_BUS); // OneWire-Instanz
DallasTemperature sensorenBus(&oneWireBus); // Übergabe OneWire-Referenz an DallasTemperature
DeviceAddress eingang = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x6C, 0x5C, 0x8B}; // 40, 255, 100, 30, 94, 108, 92, 139
DeviceAddress ausgang = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x59, 0x03, 0xC3}; // 40, 255, 100, 30, 94,  89,  3, 195


/*====================================================================================================================+
  |                                                >>>   S E T U P   <<<                                                |
  +====================================================================================================================*/
void setup() {
  Serial.begin(BITRATE);                                             // startet sM
  delay(750);                                                        // damit sich der sM etablieren kann

  //retarray = eingang;
  //drucktAdresse(retarray);

  findetAdressen(oneWireBus, 8);

  /*
    ret2array = doIt(eingang, 8);
    for (int j = 0; j < 8; j++) {
    Serial.print(retarray[j], HEX);
    Serial.print("  /  ");
    Serial.print(ret2array[j], HEX);
    Serial.println(" (doIt)");
    }
  */

} // ...setup

/*====================================================================================================================+
  |                                            >>>   F U N K T I O N E N  <<<                                           |
  +====================================================================================================================*/
/**/
//void findetAdressen(OneWire oneWire, const int sizeOfArray) {
void findetAdressen(OneWire oneWire, int sizeOfArray) {              // raises error (type int)
  byte adresse[sizeOfArray];                                         // Adress-Array e i n e s aufgespürten Sensors
  //byte adressenSensoren[][8] = {};
  byte adressenSensoren[][sizeOfArray] = {};                         // throws an error, if sizeOfArray's type is 'int'
  byte i = 0;
  byte j;
  while (oneWire.search(adresse)) {                                  // Suche nach Sensoren starten
    for (j = 0; j < sizeOfArray; j++) {
      adressenSensoren[i][j] = adresse[j];
    }
    i++;
  }

  Serial.println("--- adressenSensoren ---");
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 8; j++) {
      Serial.print(adressenSensoren[i][j], HEX);
      Serial.print(", ");
    }
    Serial.println();
  }
  Serial.println("--- ende ---");

  retarray = adressenSensoren[0];
  Serial.println("--- retarray ---");
  for (i = 0; i < 8; i++) {
    Serial.print(retarray[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
  Serial.println("--- ende ---");
  //drucktAdresse(retarray);
  //ret2array = adressenSensoren[1];
  //drucktAdresse(ret2array);
  //return retarray;                                                 // todo: if-statement
  //return ret2array;
} // ...findetAdressen
/**/

/**/
// bearbeitet bei Bedarf die eingegebene Sensor-Adresse, speichert die eingegebene Sensor-Adresse in einem Array und
// liefert diesen (modifiziert) zurück
byte* doIt(const byte nameOfArray[], const int sizeOfArray) {
  static byte returnArray[8];
  for (int i = 0; i < sizeOfArray; i++) {
    returnArray[i] = nameOfArray[i];
  }
  return returnArray;
}
/*
  byte* doIt2(const byte nameOfArray[], const int sizeOfArray) {
  static byte returnArray[8];
  for (int i = 0; i < sizeOfArray; i++) {
    returnArray[i] = nameOfArray[i] + 7;
  }
  return returnArray;
  } // ...doIt2
*/

/**/
void drucktAdresse(DeviceAddress deviceAddress) {
  for (int i = 0; i < 8; i++) {
    Serial.print("0x");
    if (deviceAddress[i] < 16) {
      Serial.print("0");
    }
    Serial.print(deviceAddress[i], HEX);
    if (i < 7) {
      Serial.print(", ");
    }
  } // ...for
} // ...void
/**/

/*====================================================================================================================+
  |                                                 >>>   L O O P   <<<                                                 |
  +====================================================================================================================*/
void loop() {
  // nix
} // ...loop

Hello,
thank you. Shame on me ... ups, too late. Doesn't matter.

Here is the error:

.ino:74:43: internal compiler error: in make_decl_rtl, at varasm.c:1313
byte adressenSensoren[][sizeOfArray] = {};

Please submit a full bug report,
with preprocessed source if appropriate.
See http://gcc.gnu.org/bugs.html for instructions.

Here is the original code (sorry, i'm beginner...):

/*#############################  #####          AUTOR: DG
#############################  #######
###                     ###  ###   ###          SKETCHNAME: uebergebeArray
###                   ###  ###                  VERSION: 0.00.1
###                 ###  ###                    LETZTE AKTUALISIERUNG: 2022-06-13
###               ###  ###
###             ###  ###                        ZWECK:
###           ###  ###       #########
###         ###  ###         #########
###       ###  ###                 ###          BIBLIOTHEK:
###     ###  ###                   ###
###   ###  ###                     ###          BOARD-SUPPORT:
#######  #############################
#####  ###############################          GERÄTE-SUPPORT:
/*====================================================================================================================+
|                                         >>>   P R Ä P R O Z E S S O R   <<<                                         |
+====================================================================================================================*/
#include <OneWire.h>                                                 // Initialisierung von 1-Kabel-Geräten
#include <DallasTemperature.h>                                       // Handling der Maxim/Dallas-1-Kabel-Geräte

/*====================================================================================================================+
|                                        >>>   D E K L A R A T I O N E N   <<<                                        |
+====================================================================================================================*/
const int BITRATE = 115200;                                          // Übertragungsrate MCU -> serieller Monitor (sM)
const byte PIN_ONEWIRE_BUS = 4;                                      // GPIO Datenbus

//const byte macAddr[]  = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x6C, 0x5C, 0x8B};
//const byte macAddr2[] = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x59, 0x03, 0xC3};

byte *retarray;
byte *ret2array;

/*====================================================================================================================+
|                                      >>>   I N I T I A L I S I E R U N G   <<<                                      |
+====================================================================================================================*/
OneWire oneWireBus(PIN_ONEWIRE_BUS); // OneWire-Instanz
DallasTemperature sensorenBus(&oneWireBus); // Übergabe OneWire-Referenz an DallasTemperature
DeviceAddress eingang = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x6C, 0x5C, 0x8B}; // 40, 255, 100, 30, 94, 108, 92, 139
DeviceAddress ausgang = {0x28, 0xFF, 0x64, 0x1E, 0x5E, 0x59, 0x03, 0xC3}; // 40, 255, 100, 30, 94,  89,  3, 195


/*====================================================================================================================+
|                                                >>>   S E T U P   <<<                                                |
+====================================================================================================================*/
void setup() {
  Serial.begin(BITRATE);                                             // startet sM
  delay(750);                                                        // damit sich der sM etablieren kann

  //retarray = eingang;
  //drucktAdresse(retarray);

  findetAdressen(oneWireBus, 8);

  /*
  ret2array = doIt(eingang, 8);
  for (int j = 0; j < 8; j++) {
    Serial.print(retarray[j], HEX);
    Serial.print("  /  ");
    Serial.print(ret2array[j], HEX);
    Serial.println(" (doIt)");
  }
  */

} // ...setup

/*====================================================================================================================+
|                                            >>>   F U N K T I O N E N  <<<                                           |
+====================================================================================================================*/
/**/
//void findetAdressen(OneWire oneWire, const int sizeOfArray) {
void findetAdressen(OneWire oneWire, int sizeOfArray) {              // raises error (type int)
  byte adresse[sizeOfArray];                                         // Adress-Array e i n e s aufgespürten Sensors
  //byte adressenSensoren[][8] = {};                             // works
  byte adressenSensoren[][sizeOfArray] = {};                         // throws an error, if sizeOfArray's type is 'int'
  byte i = 0;
  byte j;
  while(oneWire.search(adresse)) {                                   // Suche nach Sensoren starten
    for (j=0; j < sizeOfArray; j++) {
      adressenSensoren[i][j] = adresse[j];
    }
    i++;
  }

  Serial.println("--- adressenSensoren ---");
  for (i=0; i < 2; i++) {
    for (j=0; j < 8; j++) {
      Serial.print(adressenSensoren[i][j], HEX);
      Serial.print(", ");
    }
    Serial.println();
  }
  Serial.println("--- ende ---");

  retarray = adressenSensoren[0];
  Serial.println("--- retarray ---");
  for (i=0; i < 8; i++) {
    Serial.print(retarray[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
  Serial.println("--- ende ---");
  //drucktAdresse(retarray);
  //ret2array = adressenSensoren[1];
  //drucktAdresse(ret2array);
  //return retarray;                                                 // todo: if-statement
  //return ret2array;
} // ...findetAdressen
/**/

/**/
// bearbeitet bei Bedarf die eingegebene Sensor-Adresse, speichert die eingegebene Sensor-Adresse in einem Array und
// liefert diesen (modifiziert) zurück
byte* doIt(const byte nameOfArray[], const int sizeOfArray) {
  static byte returnArray[8];
  for (int i = 0; i < sizeOfArray; i++) {
    returnArray[i] = nameOfArray[i];
  }
  return returnArray;
}
/*
byte* doIt2(const byte nameOfArray[], const int sizeOfArray) {
  static byte returnArray[8];
  for (int i = 0; i < sizeOfArray; i++) {
    returnArray[i] = nameOfArray[i] + 7;
  }
  return returnArray;
} // ...doIt2
*/

/**/
void drucktAdresse(DeviceAddress deviceAddress) {
  for(int i=0; i < 8; i++) {
    Serial.print("0x");
    if(deviceAddress[i] < 16) {
      Serial.print("0");
    }
    Serial.print(deviceAddress[i], HEX);
    if(i<7) {
      Serial.print(", ");
    }
  } // ...for
} // ...void
/**/

/*====================================================================================================================+
|                                                 >>>   L O O P   <<<                                                 |
+====================================================================================================================*/
void loop() {
  // nix
} // ...loop

and yes, of course, sorry: 1.8.19. I hope i can change the title
and no: i'm using an esp32 (115200). Sorry, my fault.

I hope, everything's fine now.

Variable length arrays are not really allowed in C++ (see warnings below) and for multidimensional arrays, all bounds except the first must be given. My guess is that the combination of these is not handled by the g++ extension that allows for variable length arrays.

x.ino:5:27: warning: ISO C++ forbids variable length array 'adresse' [-Wvla]
   byte adresse[sizeOfArray];
                           ^
x.ino:6:38: warning: ISO C++ forbids variable length array 'adressenSensoren' [-Wvla]
   byte adressenSensoren[][sizeOfArray] = {};
                                      ^
x.ino:6:8: error: zero-size array 'adressenSensoren'
   byte adressenSensoren[][sizeOfArray] = {};
        ^~~~~~~~~~~~~~~~

i don't know, what your post is about (beginner, you remember ?)
just to say:

byte adressenSensoren[][8] = {};  //works
byte adressenSensoren[][sizeOfArray] = {}; // doesn't work

so long

What I am saying is that you have not found a bug, but a limitation of the programming language (as implemented by the authors of the g++ compiler).

Let us just say that using a variable length multidimensional array (e.g., your adressenSensoren) is not allowed.

Hi,
setting the serial to 115200 needs a variable greater than int. See test below when set to int.

const  int BITRATE = 115200;
const unsigned long BITRATE_2 = 115200;

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.println(BITRATE);
  Serial.println(BITRATE, HEX);
  Serial.println(" ");
  Serial.println(BITRATE_2);
  Serial.println(BITRATE_2, HEX);

}

void loop() {
  // put your main code here, to run repeatedly:

}

Should not be needed on an 32-bit processor. I was hinting at that in the frst reply but OP is using an ESP32.

1 Like

Hi, @sterretje
tks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.