This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C++ error: Class with constructor: Argument not checked

Hi,
to disable and re-enable interrupts in a safe way, I wrote the following class:

class DisableIntsShortly {
public:
  __forceinline DisableIntsShortly(){ __disable_irq(); }
  __forceinline ~DisableIntsShortly() {__enable_irq(); }
};

Thus then I should be able to protect my code with non-atomic access to interrupt variables like this:

  {
    DisableIntsShortly DI();
    ... do some things where interrupt needs to be disabled.
  }

Unfortunately this does not work - the DI is not used inside this block, therefore the optimizer seems to think that it is useless and just kills it.

To come around this, I tried it like this:

class DisableIntsShortly {
public:
  __forceinline DisableIntsShortly( int i){ __disable_irq(); i=i; }
  __forceinline ~DisableIntsShortly() {__enable_irq(); }
};

Then it works if I write this (at least in optimization level 1):

  {
    DisableIntsShortly DI( 0);
    ... do some things where interrupt needs to be disabled.
  }

Just one severe problem: If I write "DisableIntsShortly DI();" (omit the 0), then NO ERROR appears (and again the optimizer decides to just kill it - without any warning or error - could some people at Keil please solve this? Here definitely an error should appear.

(And further the optimizer should not remove class instances with custructor and/or destructor functions).

0