Hi,
I would like the compiler to treat this function as an error:
int fn ()
{
// missing return int
}
At the moment this compiler no error, not even warning.
What files hold global compiler/linker options please ?
Thanks
Hi,
I would like the compiler to treat this function as an error:
int fn ()
{
// missing return int
}
At the moment this compiler no error, not even warning.
What files hold global compiler/linker options please ?
Thanks
Why?
Inside Arduino try File->Preferences
Compiler Warning is a drop down selection in there..
good luck.. ~q
It depends on which board you're compiling for (post #4) and what your settings are (post #3).
Taking below code
void setup()
{
Serial.println(fn());
}
void loop()
{
}
int fn()
{
}
AVR based board (e.g. Uno)
"Compiler warnings All" gives a warning but does compile.
/tmp/arduino_modified_sketch_778595/sketch_apr19a.ino: In function 'int fn()':
/tmp/arduino_modified_sketch_778595/sketch_apr19a.ino:12:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
Sketch uses 1588 bytes (5%) of program storage space. Maximum is 30720 bytes.
Global variables use 188 bytes (9%) of dynamic memory, leaving 1860 bytes for local variables. Maximum is 2048 bytes.
ESP32 based board (e.g. ESP32 dev module)
"Compiler warnings None" compiles with no warning..
"Compiler warnings All" gives a warning and does not compile.
/tmp/arduino_modified_sketch_887394/sketch_apr19a.ino: In function 'int fn()':
sketch_apr19a:15:1: error: no return statement in function returning non-void [-Werror=return-type]
}
^
cc1plus: some warnings being treated as errors
exit status 1
no return statement in function returning non-void [-Werror=return-type]
Ah, sorry. Thank you. There is so few settings there I did not even look.
Interesting, Thanks.
Here
c:\Users\frank\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\
Hm, when the same toolchain is used for all boards I would expect the same result. This seems a bit odd. It suggests there is additional, per board compiler options files. Interesting. Thanks.
There are per board package (see post #4). The used toolchains and their configurations are not the responsibility of the IDE but of the board package maintainers (in case of official Arduino boards, it will be Arduino).
I think that you can create a per board configuration but I suspect that it will give you a lot of grey hairs; on the other hand your recent posting history indicates that you seem to have sufficient interest in this type of stuff so it might be worth investigating. Be aware that if modify the existing board package and you decide to update that package, your changes will be lost.
Hi @frank_11.
I'll provide instructions you can follow to configure the compiler to upgrade the "no return statement in function returning non-void
" warning to an error when compiling for any board of the "Arduino AVR Boards" platform. This is done by adding the -Werror=return-type
flag to the GCC commands Arduino IDE runs to compile the .ino
, C, and C++ files of your sketch program.
One approach would be to edit the platform's platform.txt
configuration file directly. However, a better approach is to instead inject your modifications via a platform.local.txt
file, because this means you can accomplish the modification without the risk of introducing any unintended changes that might occur with the alternative approach of editing the existing platform configuration files.
compiler.c.extra_flags=-Werror=return-type
compiler.cpp.extra_flags=-Werror=return-type
c:\Users\frank\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\platform.local.txt
AppData>
folder by default. You can make it visible by starting Windows "File Explorer", opening the "View" menu, then checking the box next to "☐ Hidden items".Now compile your sketch again. This time the compilation should fail with the "no return statement in function returning non-void
" error.
If you also use boards of other platforms and would like to make the same adjustment, you can probably just copy that platform.local.txt
file to the installation folder of the other platforms. Although supporting the injection of arguments into the compilation command templates via these "extra_flags
" properties is a common convention in Arduino boards platforms, there is nothing in the platform framework that mandates it, or ensures the implementation of the feature is done correctly by the platform developer, so it is possible you might run into problems with certain 3rd party platforms (you shouldn't have any problems doing it with the official platforms). If so, we can provide advice about the appropriate approach for modifying those platforms.
Your modifications to a platform will be lost any time you update to a new version of the platform via the Arduino IDE Boards Manager.
You might want to save a copy of the platform.local.txt
file to a safe location. You can then simply copy the file back into the platform installation folder after an update and then restart the IDE in order to easily re-apply your modifications.
Hm, when the same toolchain is used for all boards
Hm, now I am thinking that different toolchains are used for ESP and Arduino boards as they use different MCUs (still GCC but ESP backend). I tried but could not find info how it actually works - I mean to install toolchain for ESP. Does IDE do it for you when it sees ESP board connected ?
Good point. Now after I managed to build all libs into .a I better back them up. Thanks.
What do you mean ?
Installing the toolchain is done when you install the board package. Selection of the right toolchain is done when you select a board in tools / board.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.