Skip to content

Add attribute unused to PT_YIELD_FLAG to avoid warnings when compiling in some use cases

When using the protothreads library in the Arduino IDE, some use cases get a warning about PT_YIELD_FLAG being set but not used:

LEDToggleWithProtoThreads.ino:8:3: note: in expansion of macro 'PT_BEGIN'
    8 |   PT_BEGIN(pt);
      |   ^~~~~~~~
Arduino\libraries\Protothreads\src/pt.h:115:56: warning: variable 'PT_YIELD_FLAG' set but not used [-Wunused-but-set-variable]
  115 | #define PT_BEGIN(pt) {  __attribute__((nounused)) char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)
      |                                                        ^~~~~~~~~~~~~
Arduino\LEDToggleWithProtoThreads\LEDToggleWithProtoThreads.ino:8:3: note: in expansion of macro 'PT_BEGIN'
    8 |   PT_BEGIN(pt);
      |   ^~~~~~~~

when using the following function as in ProtoThreads:

int slowBlinkThread(struct pt* pt)
{
  PT_BEGIN(pt);
 
  while(true)  {
    setLEDRed(true);
    PT_SLEEP(pt, 1000);
    setLEDRed(false);
    PT_SLEEP(pt, 1000);
   }

  PT_END(pt);
}

This merge request adds a compiler attribute of unused to the char PT_YIELD_FLAG so when in user-code it isn't used, there is no compiler warning.

Merge request reports

Loading