Object with volatile private member

Hi guys,
I'm writing code for Arduino, for interrupt function. Any variable must be volatile, so in case with no object it will look like this:

1
2
3
4
5
6
volatile int var;

void interrupt()
{
    var++;
}


But in next case I'm not sure should I create object with volatile tag, or modifier function, or just private variable?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class objclass {
public:
addValue(int value) { var += value; }

private:
int var;
};


objclass object;

void interrupt()
{
    object.addValue(1);
}


Where I should put volatile? Thanks!
1
2
3
4
5
6
7
8
9
10
struct A {

    volatile int i = 0 ;
    int j = 0 ;
};

volatile A a1 ; // all members of a1 are volatile:
                // both a1.i and a1.j are of type 'volatile int'

A a2 ; // a2.i is volatile, a2.j is not 
Thanks for explonation
Topic archived. No new replies allowed.