Object with volatile private member

Nov 19, 2018 at 2:28am
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!
Nov 19, 2018 at 2:38am
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 
Nov 19, 2018 at 3:22am
Thanks for explonation
Topic archived. No new replies allowed.