Skip to content

warning: using value of assignment with 'volatile' #200

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

Open
hoffmakl1961 opened this issue Apr 1, 2025 · 1 comment
Open

warning: using value of assignment with 'volatile' #200

hoffmakl1961 opened this issue Apr 1, 2025 · 1 comment

Comments

@hoffmakl1961
Copy link

hoffmakl1961 commented Apr 1, 2025

Hello everyone,
I get the following warning when compiling:

In file included from C:\Users...\Documents\Arduino\Heizung\Thermostat\Thermostat_Wohnen_V12\Thermostat_Wohnen_V12.ino:22:
c:\Users...\Documents\Arduino\libraries\TaskScheduler\src/TaskScheduler.h: In member function 'void Task::set(long unsigned int, long int, TaskCallback, TaskOnEnable, TaskOnDisable)':
c:\Users...\Documents\Arduino\libraries\TaskScheduler\src/TaskScheduler.h:626:34: warning: using value of assignment with 'volatile'-qualified left operand is deprecated [-Wvolatile]
626 | iSetIterations = iIterations = aIterations;

c:\Users...\Documents\Arduino\libraries\TaskScheduler\src/TaskScheduler.h: In member function 'void Task::setIterations(long int)':
c:\Users...\Documents\Arduino\libraries\TaskScheduler\src/TaskScheduler.h:642:34:
warning: using value of assignment with 'volatile'-qualified left operand is deprecated [-Wvolatile]
642 | iSetIterations = iIterations = aIterations;
| ~~~~~~~~~~~~^~~~~~~~~~~~~

My Environment:
Ardunino IDE 2.3.4 / ESP32 Dev Module, TaskScheduler 3.8.5 ([arkhipenko]
let me know, if you need more informations

@hoffmakl1961
Copy link
Author

The compiler warns that an assignment to a volatile-qualified variable is no longer recommended. This means that the expression:
iSetIterations = iIterations = aIterations;
is problematic if iIterations has been declared as volatile.

Why does the error occur?

  • volatile is used to inform the compiler that a variable can change unexpectedly (e.g. due to interrupts or external hardware).
  • In newer C++ standards, direct chained assignment (=) with volatile variables is considered obsolete as it can lead to unpredictable behaviour.

Solution:
Instead of writing the assignment in one line, the values should be assigned one after the other:
iIterations = aIterations; // Set the value first
iSetIterations = iIterations; // Then assign the set value

TaskScheduler.h
line 626 and 642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant