B4R Question error: control reaches end of non-void function

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

with oldest B4R I can compile my software, but with B4R 4.0, I get:
rHttpUtils2\Objects\src\rESP8266OTA.cpp:29:15: error: control reaches end of non-void function [-Werror=return-type]
29 | WiFiClient client;
| ^~~~~~
cc1plus.exe: some warnings being treated as errors
Error during build: exit status 1

what does it mean, please? Can I secure this situation with new version B4R. ESP8266Wifi LIB I have 1.59 version.
Best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
It should work with the versions listed here: https://www.b4x.com/b4r.html
Dear friends, Mr. Erel,

I have installed last version of B4R, last version of all items from here: B4R Instalation
I am using this code rESP8266OTA.cpp :
#include "B4RDefines.h"

namespace B4R {
B4RString* B4RESP8266OTA::StringToB4R(String* o) {
PrintToMemory pm;
B4RString* s = B4RString::printableToString(NULL);
pm.print(*o);
StackMemory::buffer[StackMemory::cp++] = 0;
return s;
}
B4RString* B4RESP8266OTA::HTTPUpdate(B4RString* server, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError())+" "+ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
}
B4RString* B4RESP8266OTA::HTTPUpdate2(B4RString* server, int port, B4RString* filename, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data, port, filename->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError())+" "+ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
}
void B4RESP8266OTA::ESPRestart(void) {
ESP.restart();
}

}

I get same result, same error as I describe above.:
1725463961579.png

Is here some new OTA lib?

Best regards
p4ppc
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Could it be that your switch statements fail to match, and the code drops through without a return statement.

B4X:
B4RString* B4RESP8266OTA::HTTPUpdate(B4RString* server, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError())+" "+ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
return StringToB4R("ERROR");  // incase the switch doesn't match anything.
}

Or simply add a default: to the switch statement.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear Daestrum,

thank you for your answer. I got same result, "rHttpUtils2\Objects\src\rESP8266OTA" :
I am using this code in rESP8266OTA.cpp:
#include "B4RDefines.h"
namespace B4R {
B4RString* B4RESP8266OTA::StringToB4R(String* o) {
PrintToMemory pm;
B4RString* s = B4RString::printableToString(NULL);
pm.print(*o);
StackMemory::buffer[StackMemory::cp++] = 0;
return s;
}
B4RString* B4RESP8266OTA::HTTPUpdate(B4RString* server, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError()) + " " + ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
// Return "ERROR" in case no switch case matched
s = "ERROR";
return StringToB4R(&s);
}
B4RString* B4RESP8266OTA::HTTPUpdate2(B4RString* server, int port, B4RString* filename, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data, port, filename->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError()) + " " + ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
// Return "ERROR" in case no switch case matched
s = "ERROR";
return StringToB4R(&s);
}
void B4RESP8266OTA::ESPRestart(void) {
ESP.restart();
}
}
Please very much for help,
best regards
p4ppc
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Now your error looks like a missing header file - the one that contains WiFiClient

you probably need to add

c++:
#include "WiFiClient.h"
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear Daestrum,

same situation:
My rESP8266OTA.cpp code:
#include "WiFiClient.h"
#include "B4RDefines.h"

namespace B4R {
B4RString* B4RESP8266OTA::StringToB4R(String* o) {
PrintToMemory pm;
B4RString* s = B4RString::printableToString(NULL);
pm.print(*o);
StackMemory::buffer[StackMemory::cp++] = 0;
return s;
}
B4RString* B4RESP8266OTA::HTTPUpdate(B4RString* server, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError())+" "+ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
}
B4RString* B4RESP8266OTA::HTTPUpdate2(B4RString* server, int port, B4RString* filename, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data, port, filename->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError())+" "+ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
}
void B4RESP8266OTA::ESPRestart(void) {
ESP.restart();
}

}

------------------------------
Errors:
rHttpUtils2\Objects\src\rESP8266OTA.cpp:30:15: error: control reaches end of non-void function [-Werror=return-type]
30 | WiFiClient client;
| ^~~~~~
cc1plus.exe: some warnings being treated as errors
Error during build: exit status 1

\rHttpUtils2\Objects\src\rESP8266OTA.cpp: In member function 'B4R::B4RString* B4R::B4RESP8266OTA::HTTPUpdate2(B4R::B4RString*, int, B4R::B4RString*, bool)':

\rESP8266OTA.cpp: In member function 'B4R::B4RString* B4R::B4RESP8266OTA::HTTPUpdate(B4R::B4RString*, bool)':
C:\Users\Owner\Desktop\project\rHttpUtils2\Objects\src\rESP8266OTA.cpp:14:15: error: control reaches end of non-void function [-Werror=return-type]

"C:\\Users\\Owner\\AppData\\Local\\Temp\\arduino\\sketches\\73783ED0AC96ED4059B19C3A489A6DB3\\sketch\\src.ino.cpp.o"
C:\Users\Owner\Desktop\project\rHttpUtils2\Objects\src\rESP8266OTA.cpp: In member function 'B4R::B4RString* B4R::B4RESP8266OTA::HTTPUpdate(B4R::B4RString*, bool)':
C:\Users\Owner\Desktop\project\rHttpUtils2\Objects\src\rESP8266OTA.cpp:14:15: error: control reaches end of non-void function [-Werror=return-type]
14 | WiFiClient client;
| ^~~~~~
C:\Users\Owner\Desktop\project\rHttpUtils2\Objects\src\rESP8266OTA.cpp: In member function 'B4R::B4RString* B4R::B4RESP8266OTA::HTTPUpdate2(B4R::B4RString*, int, B4R::B4RString*, bool)':
C:\Users\Owner\Desktop\project\rHttpUtils2\Objects\src\rESP8266OTA.cpp:30:15: error: control reaches end of non-void function [-Werror=return-type]
30 | WiFiClient client;
| ^~~~~~
cc1plus.exe: some warnings being treated as errors
Using library EspSoftwareSerial at version 8.0.1 in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SoftwareSerial
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi
Using library ESP8266httpUpdate at version 1.3 in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266httpUpdate
Using library ESP8266HTTPClient at version 1.2 in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266HTTPClient
Using library EEPROM at version 1.0 in folder: C:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\EEPROM
Error during build: exit status 1
[92mUsed library[0m [92mVersion[0m [90mPath[0m
[93mEspSoftwareSerial[0m 8.0.1 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SoftwareSerial[0m
[93mESP8266WiFi[0m 1.0 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi[0m
[93mESP8266httpUpdate[0m 1.3 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266httpUpdate[0m
[93mESP8266HTTPClient[0m 1.2 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266HTTPClient[0m
[93mEEPROM[0m 1.0 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\EEPROM[0m
[92mUsed platform[0m [92mVersion[0m [90mPath[0m
[93mesp8266:esp8266[0m 3.1.2 [90mC:\Users\Owner\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2[0m

Please for help, with older B4A (3.90) is compilation OK,
best regards
p4ppc
 
Last edited:
Upvote 0
Top