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

Arduino-generated temp code throws errors: exit status 1 variable or field 'xxx' declared void #8257

Closed
dsyleixa opened this issue Dec 2, 2018 · 10 comments
Labels
Type: Bug Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug

Comments

@dsyleixa
Copy link

dsyleixa commented Dec 2, 2018

Arduino-generated temp code throws errors:
exit status 1 variable or field 'displaylist' declared void
(1.8.5)

#include <lfoo.h>
#include <lbas.h>
#include <lother.h>
#include <Adisplay.h>
Adisplay display;


typedef struct  {
   int foo;
   char bas;
} list;

list mList00;

//  display Funktion
**void  displaylist(list mList) {   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<**
    Serial.println(mList.foo);
    Serial.println(mList.bas);
}

//

void setup() {
   mList00.foo=100;
   mList00.bas=3;

  displaylist(mList00);   
   //
}

Only if I put the struct definition to the most upper top (i.e., top of the #defines), then it compiles.

@per1234
Copy link
Collaborator

per1234 commented Dec 3, 2018

Please always test using the hourly build of the Arduino IDE before reporting issues here:
https://www.arduino.cc/en/Main/Software#hourly
Otherwise, you might be encountering a bug that has already been fixed.

After doing so, please comment here to let us know whether the problem was resolved or not. If not, then you should provide a Minimal, Complete, and Verifiable Example (MCVE) we can use to reproduce the problem. The code you posted is not very useful for this purpose.

@per1234 per1234 added the Waiting for feedback More information must be provided before we can proceed label Dec 3, 2018
@dsyleixa
Copy link
Author

dsyleixa commented Dec 3, 2018

ok, ftm I can't install a 1.8.7 version, it takes too much time and too many efforts, so for now this is a cutdown test code.
If anyone has a new 1.8.7 he may try, otherways I'll try to test a 1.8.7 in a couple of days by my own:

/*
 *********** This code is for the ESP8266 *********** 
 *          Change GPIOs for different boards
*/


// I2C
#include <Wire.h>         // Incl I2C comm, but needed for not getting compile error

// TFT
#include <Adafruit_SSD1306.h>    //  
#include <Adafruit_GFX.h>   //  
 

Adafruit_SSD1306 display(10);  //  

char LINELEN = 8;
char LINENUM = 4;

typedef struct  {
   char line[8][20] = {"line0_67 9012345678" ,"line1_6"      ,"line2_67" ,
                       "line3_6789012345678" ,"line4_6789012345678" ,"line5_6789012345678" ,
                       "line6_6789012345678" ,"line7_6789012345678" };
   char act=0, top=0, btm=top+LINENUM;
   char subl[12]="           ";
} list;

list mList00;


void strcpysubl(char * dest, char * source, char pos) {
   byte l;
   memset(dest,' ',sizeof(dest));
   strncpy( dest+1, source+pos, LINELEN );     
}


void  displayMenulist(list mList) {
  byte l;

  for(byte i=0; i<5; i++) { 
    strcpysubl( mList.subl, mList.line[i], 0);     
      l=10 + i*13;
      display.setCursor( 0, l);  display.print(mList.subl);
      Serial.println(mList.subl);      
  } 
  display.display();
}  
                    

void setup(void)
{
 // Start Serial
 Serial.begin(115200);
 delay(2000); // wait for Serial()
  
 // Start Wire (SDA, SCL)
 Wire.begin(D2, D1);   

  // SSD1306 Init  
  display.begin();  // Switch OLED
  display.clearDisplay();  // Clear the buffer.
  
  display.setFont(); 
  displayMenulist(mList00);     
}


void loop() {     
}

@facchinm
Copy link
Member

facchinm commented Dec 3, 2018

The sketch compiles cleanly with IDE master (so it also will with 1.8.7 since the builder didn't change) and esp8266 core 2.4.2.
Closing as solved in mainline.

@facchinm facchinm closed this as completed Dec 3, 2018
@dsyleixa
Copy link
Author

dsyleixa commented Dec 3, 2018

thank you for your efforts, strangely I just now can't reproduce this issue with the cut-down code either.

@dsyleixa
Copy link
Author

dsyleixa commented Dec 3, 2018

nonetheless, I am clueless -
with the complete code it still don't work, unless I put the struct to the most upper position.
actually only the function
void dashboard(byte mode)
is in between but which isn't ever called in here.

/*
 *
 *      using SSD1306 Adafruit library  
 * for a ssd1306 OLED Display  with the ESP8266 board
 *
 *********** This code is for the ESP8266 *********** 
 * 
*/

// i2c
#include <Wire.h>         // Incl I2C comm, but needed for not getting compile error
#define ESPSDA D2         // defaults
#define ESPSCL D1         // 

// TFT
#include <Adafruit_SSD1306.h>
//#include <ESP_SSD1306.h>    // Modification of Adafruit_SSD1306 for ESP8266 compatibility
#include <Adafruit_GFX.h>   // Needs a little change in original Adafruit library (See README.txt file)
#include <Fonts/FreeSans12pt7b.h>            // 
#include <Fonts/FreeSansBold12pt7b.h>        // 
#include <Fonts/FreeSans9pt7b.h>             //
#include <Fonts/FreeMono12pt7b.h>            //   
#include <Fonts/FreeMono9pt7b.h>    
// Pin definitions
#define OLED_RESET 10  // GPIO10=D12 Pin RESET signal (virtual)

Adafruit_SSD1306 display(OLED_RESET);
//Adafruit_SSD1306 display(128, 64, &Wire, D0);
//ESP_SSD1306 display(OLED_RESET); // FOR I2C


//----------------------------------------------------------------------------
// OLED dashboard
//----------------------------------------------------------------------------

void dashboard(byte mode) {     

  display.clearDisplay();
  display.setFont();

  if (mode == 0) {
    display.setFont();  // h=8.0 pt
    display.setCursor( 0,  0);  display.print(" 0 Hello World 1");
    display.setCursor( 0,  8);  display.print(" 8 Hello World 2");
    display.setCursor( 0, 16);  display.print("16 Hello World 3");
    display.setCursor( 0, 24);  display.print("24 Hello World 4");
    display.setCursor( 0, 32);  display.print("32 Hello World 5");
    display.setCursor( 0, 40);  display.print("40 Hello World 6");
    display.setCursor( 0, 48);  display.print("48 Hello World 7");
    display.setCursor( 0, 56);  display.print("56 Hello World 8");
    display.setCursor( 0, 64);  display.print("64 Hello World 9");
  }
  else
  if (mode == 1) {
    display.setFont();  // h=9.0 pt
    display.setCursor( 0,  0);  display.print(" 0 Hello World 1");
    display.setCursor( 0,  9);  display.print(" 9 Hello World 2");
    display.setCursor( 0, 18);  display.print("18 Hello World 3");
    display.setCursor( 0, 27);  display.print("27 Hello World 4");
    display.setCursor( 0, 36);  display.print("36 Hello World 5");
    display.setCursor( 0, 45);  display.print("45 Hello World 6");
    display.setCursor( 0, 54);  display.print("54 Hello World 7");
    display.setCursor( 0, 63);  display.print("63 Hello World 8");
    display.setCursor( 0, 72);  display.print("72 Hello World 9");
  }
  else  
  if (mode == 8) {
    display.setFont(&FreeMono9pt7b); // h=13.10pt
    display.setCursor( 0, 10);  display.print("10 Hello M9");
    display.setCursor( 0, 23);  display.print("23 Hello M9");
    display.setCursor( 0, 36);  display.print("36 Hello M9");
    display.setCursor( 0, 49);  display.print("49 Hello M9");
    display.setCursor( 0, 62);  display.print("62 Hello M9");
  }
  else
  if (mode == 9) {
    display.setFont(&FreeSans9pt7b); // h=16.12pt
    display.setCursor( 0, 12);  display.print("12 Hello FS9-7");
    display.setCursor( 0, 28);  display.print("28 Hello FS9-7");
    display.setCursor( 0, 44);  display.print("44 Hello FS9-7");
    display.setCursor( 0, 60);  display.print("60 Hello FS9-7");
  }
  else
  if (mode ==12) {
    display.setFont(&FreeSans12pt7b); // h=21.17pt
    display.setCursor( 0, 17);  display.print("17 HelloS12");
    display.setCursor( 0, 38);  display.print("38 HelloS12");
    display.setCursor( 0, 59);  display.print("59 HelloS12");
  }
  display.display();
  display.setFont();
}
  



//----------------------------------------------------------------------------
// OLED menu
//----------------------------------------------------------------------------

const char LINELEN = 8;
const char LINENUM = 4;
const char MENULEN = 8;


typedef struct  {
   char line[8][20] = {"line0_67 9012345678" ,"line1_6"      ,"line2_67" ,
                       "line3_6789012345678" ,"line4_6789012345678" ,"line5_6789012345678" ,
                       "line6_6789012345678" ,"line7_6789012345678" };
   char act=5, top=0, btm=top+LINENUM;
   char subl[12]="           ";
} list;

list mList00;


void strcpysubl(char * dest, char * source, char pos) {
   byte l;
   memset(dest,' ',sizeof(dest));
   dest[12]=0;
   strncpy( dest+1, source+pos, LINELEN );   
   if(strlen(source)>(8+pos) )  dest[9] = '~' ; 
   else for( l=strlen(dest); l<=9; l++) dest[l]=' ';    
   dest[10] = '.';
   dest[11] = 0;
}


void  displayMenulist(list mList) {
  int8_t start;
  byte l;
  
  if(mList.act>LINENUM) start=_min(mList.act, MENULEN-LINENUM-1);
  else start=0;
  
  for(byte i=0+start; i<5+start; i++) { 
    strcpysubl( mList.subl, mList.line[i], 0); 
      
      if(i==mList.act) { 
        //display.setTextColor(BLACK, WHITE);
        mList.subl[0]='>';
      }
      //else display.setTextColor(WHITE);
      l=10 + (i-start)*13;
      display.setCursor( 0, l);  display.print(mList.subl);
      Serial.println(mList.subl);
      //display.display();
  } 
  display.display();
}  
                 

                     

void setup(void)
{
  // Start Serial
  //pinMode(D3, OUTPUT);       // + LED_BUILTIN 
   
  pinMode(D7, OUTPUT);
  pinMode(D8, OUTPUT);
  Serial.begin(115200);
  delay(2000); // wait for Serial()
  
  // Start Wire (SDA, SCL)
  Wire.begin(ESPSDA,ESPSCL);  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  // SSD1306 Init  
  display.begin(SSD1306_SWITCHCAPVCC);  // Switch OLED
  display.setRotation(2);  
  display.clearDisplay();  // Clear the buffer.

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello, world!");  
  display.display();

  delay(1000);
  display.clearDisplay(); 
  display.display();

  for(byte i=0; i<8; i++) { Serial.println(mList00.line[i]); }
  
  Serial.print("act="); Serial.println((byte)mList00.act);

  display.setFont(&FreeMono9pt7b); // h=13.10pt
  displayMenulist(mList00);
     
 // display.display();
  delay(2000);
  
}


void loop() {
   

}

@per1234
Copy link
Collaborator

per1234 commented Dec 3, 2018

This is what a MCVE looks like for this issue:

void dashboard() {}

typedef struct {
  byte x = 42;
} list;

void  displayMenulist(list mList) {}

void setup() {}
void loop() {}

Do you see how much more simple that makes it for us to reproduce the problem? No need to find and install unnecessary libraries. No distracting code that has nothing to do with the bug. No confusion over which board you need to select.

Here's what the code looks like after arduino-builder has generated the function prototypes:

#include <Arduino.h>
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
void dashboard();
#line 7 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
void displayMenulist(list mList);
#line 9 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
void setup();
#line 10 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
void loop();
#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\arduino_modified_sketch_76316\\sketch_dec03a.ino"
void dashboard() {}

typedef struct {
  byte x = 42;
} list;

void  displayMenulist(list mList) {}

void setup() {}
void loop() {}

You can see the prototype for displayMenulist was inserted above the declaration of the list type, thus the error.

The error does not occur when compiling using Arduino IDE 1.9.0 beta build 88, which indicates that arduino-preprocessor does correctly handle the function prototype generation in this situation.

The workaround is to manually add the displayMenulist function prototype at the correct location in your code, after the declaration of list:

void  displayMenulist(list mList);

arduino-builder does not do prototype generation for any function that already has a prototype.

@dsyleixa
Copy link
Author

dsyleixa commented Dec 3, 2018

thanks for your efforts, too.
Indeed I'm surprised how much the code could be cut down to reproduce the error considering that even the former code tested by facchinm was not able to show it.
Now I know what has happened for that: in order to cut it down before as much as possible, I deleted the unused dashboard function (belated, to make it more compact and better readable) which actually was crucial for producing that compile error.
Having said that, I now see the issue clearly of course and how to fix that, thanks again.
I have to admit that migrating to newer IDE versions is not trivial because I cannot move my portable Windows version to my RaspberryPi easily with respect to my board installations, and reinstalling all and everything on either target platform (especially 3rd party boards like ESPs and Adafruit M0+M4+Huzzah) is really causing headaches, tbh.

@per1234
Copy link
Collaborator

per1234 commented Dec 3, 2018

I'm not recommending you to migrate to the hourly or beta builds. The workaround of adding the function prototype is the best solution and that will work fine with your current Arduino IDE 1.8.5. There are some very nice improvements made in the Arduino IDE on every release and I think the upcoming 1.8.8 will be a good one but I do understand wanting to stick with the version that's working for you. We've already discussed your issue with transferring your installation between the Windows machine and RPi on the Arduino Forum.

However, as I said before, you should take the time to verify that bugs you find still occur in the hourly build before reporting them here. That doesn't mean you need to switch to using the hourly build full time. You can leave your existing installation in place. You only need to download and extract the hourly build, then run it long enough for a quick test. After that you can go back to whichever IDE version you are comfortable with.

Currently, the situation is a little confusing because there is an hourly build and a beta build. It is a bit onerous to need to download the latest version and test with both of those and so I feel that it's reasonable to test only with the hourly build. In this case the beta build is especially relevant since it uses a new sketch preprocessor. Hopefully soon the work in the beta build will get merged and we will be back to only having the hourly build to test with.

@dsyleixa
Copy link
Author

dsyleixa commented Dec 3, 2018

ok, I see that the hourly build is esasier to use for checking than I assumed, even if the 1.8.7 was supposed to produce the same error ;)
But I agree to your statements about testing of course, thx! 8)

@per1234
Copy link
Collaborator

per1234 commented Dec 3, 2018

In this very specific case and moment in time, Arduino IDE 1.8.7 is equivalent to the hourly build since they are currently both using the same version of arduino-builder, which does the function prototype generation. However, that could change at any time. That also only applies to the particular processes handled by arduino-builder rather than other bugs that could be caused by problems in the Arduino IDE's Java code. So you should not assume that's always the case.

In the case of a bug that you know to be a failure of prototype generation, you could check the arduino-builder release page to see which is the most recent version, then compare that to the version used by the latest Arduino IDE release to see if it's the same. Of course, at some point in the future, function prototype generation will be handled by arduino-preprocessor so at that time you will instead need to check that version. As you can see, it's much more simple in the end just to use the hourly build for testing.

@per1234 per1234 added Type: Bug Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug and removed Waiting for feedback More information must be provided before we can proceed labels Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug
Projects
None yet
Development

No branches or pull requests

3 participants