protothreads-cpp
protothreads-cpp copied to clipboard
Suggest using volatile attribute on ptYielded
If protothread does not have any PT_YIELD() in its Run method then compiler produces a warning, that ptYielded is set but never used.
I suggest using volatile attribute on ptYilded so compiler won't optimize (void) ptYielded; statement and won't produce any warnings.
#define PT_BEGIN() bool volatile ptYielded = true; (void) ptYielded; switch (_ptLine) { case 0:
For example I have this code without any PT_YILED()
PT_BEGIN();
PT_SPAWN(task1);
PT_SPAWN(task2);
readtask.Run();
task3.Run();
PT_WAIT_THREAD(readtask);
PT_WAIT_THREAD(task3);
//PT_YIELD();
PT_END();
Sorry for not responding to this earlier! I'm curious (and I haven't written a lot of C for a while): why doesn't the (void) ptYielded cause the compiler to not produce a warning here?
Alternatively, you could use __attribute__((unused)).
why doesn't the
(void) ptYieldedcause the compiler to not produce a warning here?
This will cast it to the type void. The compiler then seems to think that the value is used because it was casted.