Difference in compilation between arduino 1.8.19 and IDE 2

Hello,
I'm writing a post about differences in compilation between Arduino 1.8.19 and 2.0.0.
This code, compilated with arduino 1.8.19, does not return reports of possible compilation errors, while IDE 2.0 returns some errors (I will attach errors).
Is it possible to correct what the compilation of IDE 2.0 refers to? Thank you in advance.

Following the error:
ERROR 1:
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino: In function 'void loop()':
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino:603:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (( millis()<lastT1 ) and (FirstLoop == 0)) return;
~~^
CODE:
long lastT1=0; // update display timer1
long lastT2=0; // update display timer2
lastT2 = millis(); // set T2 display refresh

ERROR 2:
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino:699:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (millis() > (lastTpep + T_pepHOLD)) { // clear the peak after hold time
~^~~~~~~~~~~~~~~~
CODE:
long lastTpep = 0; // update PEP display
#define T_pepHOLD 600 // msec pep hold time before return
lastT2 = millis(); // set T2 display refresh

ERROR:
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino:831:36: warning: second operand of conditional expression has no effect [-Wunused-value]
constrain (temp,0,99);
^
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino:831:36: warning: second operand of conditional expression has no effect [-Wunused-value]
C:\Users\jolite\Documents\Arduino\sketch_aug19a\sketch_aug19a_copy_20220819204610\sketch_aug19a_copy_20220819204610.ino:831:36: warning: third operand of conditional expression has no effect [-Wunused-value]

CODE:
temp = ((Thermister(1023 - analogRead(IN_NTC))) + 0.5);

Change those to 'unsigned long'. The values returned by millis() and micros() are unsigned long.

This should be:
if (millis() - lastTpep > T_pepHOLD)) { // clear the peak after hold time
Always subtract time values to compare to an interval.

Hello, thanks for help.
this error
constrain (temp,0,99);
have compiled with temp=constrain (temp,0,99); now ok.
another two resolve as you suggested,
Jack

The differences are likely only the result of different configurations of the two applications.

Try this:

  1. Start Arduino IDE 1.8.19
  2. Select File > Preferences... from the Arduino IDE menus.
  3. Select "All" from the "Compiler warnings" menu.
  4. Click the OK button.
  5. Compile your sketch in Arduino IDE 1.8.19
  6. Wait for the compilation to finish.

Check the contents of the black output panel at the bottom of the Arduino IDE 1.8.19 window. Do you now see the same warnings you noticed when using Arduino IDE 2.0.0?

  1. Start Arduino IDE 2.x
  2. Select File > Preferences... from the Arduino IDE menus.
  3. Select "None" from the "Compiler warnings" menu.
  4. Click the OK button.
  5. Compile your sketch in Arduino IDE 2.x
  6. Wait for the compilation to finish.

Check the contents of the black output panel at the bottom of the Arduino IDE 2.0.0 window. Do you now find that no warnings are shown, the same behavior as what you reported here from Arduino IDE 1.8.19?

My recommendation is to always set this preference to "All", whether using Arduino IDE 1.8.19 or 2.x. The reason is that compiler warnings can sometimes indicate serious problems in your code that would be difficult to find otherwise.

It is important to understand the difference between warnings and errors. A warning is the compiler telling you there is something in the code that could possibly cause a problem but doesn't cause the compilation to fail. An error is a problem with the code that causes compilation to fail. In this case you have posted warnings, not errors. In order to avoid confusion, we should be careful to use the appropriate terminology when communicating about technical subjects.

The output will show warnings that come from any of the code being compiled, which includes the "core" that defines the standard Arduino language API for the board as well as any libraries being used by your sketch.

You should pay attention to warnings and fix them in your own code whenever possible. Unfortunately some core and library authors don't hold themselves to such high standards so sometimes you do just need to ignore a warning that is produced by code you didn't write. That can be quite annoying since you must sort though the warnings from other people's sloppy code to make sure none are coming from your own code.

You may decide it's worth editing the source of the library to fix the warning. If you do so, it's a good idea to submit a pull request for the fix to the library's repository to solve the problem upstream, otherwise the warnings will come back whenever you update to a new release of the library. This will also benefit all the other users of the library.

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