rule 13.2: are const volatile variables volatile or not?

Moderators: misra-c, david ward

Post Reply
ggoulas
Posts: 5
Joined: Tue Jun 09, 2009 1:43 pm
Company: The MathWorks

rule 13.2: are const volatile variables volatile or not?

Post by ggoulas » Fri Sep 22, 2017 3:05 pm

Hi,

Quick question about rule 13.2:
the following variable:

const volatile uint8_t myvar = 0;

should it be considered as volatile or non-volatile in the context of rule 13.2 ?

thank you.

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: rule 13.2: are const volatile variables volatile or not?

Post by misra-c » Tue Oct 24, 2017 2:07 pm

The above initialization is compliant with rule 13.2, but it is assumed that the question refers to the use of "myvar" in other expressions.

"myvar" should then be considered as having a volatile-qualified type. For example:

Code: Select all

  const volatile uint8_t myvar = 0;
  volatile uint8_t var2 = 0;
  uint8_t x = 3;
  uint8_t y;
  
  y = var2 + x;      // compliant - one read access of volatile-qualifed type.
  y = var2 + myvar;  // non-compliant - more than one read access of volatile-qualified type.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.13 Side effects”