why volatile can repeat declare?

#include <stdio.h> volatile int isInit_STD; volatile int isInit_STD; int main() { printf("v-%d-addr%x\n",isInit_STD,&isInit_STD); isInit_STD = 1; printf("v-%d-addr%x\n",isInit_STD,&isInit_STD); return 0; } and the result is: v-0-addr387fd040 v-1-addr387fd040 why volatile can repeat declare? It turns out they are all the same, the same address. If one of them deletes the ‘volatile’, that can’t be compiled success. I want… Read More why volatile can repeat declare?

Can using foreach of CopyOnWriteArrayList cause ConcurrentModificationException in java?

I look to java 11 implementation of .foreach method in CopyOnWriteArrayList public void forEach(Consumer<? super E> action) { Objects.requireNonNull(action); for (Object x : getArray()) { @SuppressWarnings("unchecked") E e = (E) x; action.accept(e); } } I see that it just loops the array without any locks. Can add() or remove() performed concurrently with foreach give a… Read More Can using foreach of CopyOnWriteArrayList cause ConcurrentModificationException in java?

indexing an element from a volatile struct doesn't work in C++

I have this code: typedef struct { int test; } SensorData_t; volatile SensorData_t sensorData[10]; SensorData_t getNextSensorData(int i) { SensorData_t data = sensorData[i]; return data; } int main(int argc, char** argv) { } It compiles with gcc version 8.3, but not with g++. Error message: main.c: In function ‘SensorData_t getNextSensorData(int)’: main.c:8:34: error: no matching function for… Read More indexing an element from a volatile struct doesn't work in C++

Should I qualify pointer parameters with volatile if they may be changed during the execution of a function?

Say I have the function int foo(int * const bar){ while(!*bar){ printf("qwertyuiop\n"); } } where I intend to change the value at bar to something other than 0 to stop this loop. Would it be appropriate to instead write it as below? int foo(int volatile * const bar){ while(!*bar){ printf("qwertyuiop\n"); } } >Solution : volatile… Read More Should I qualify pointer parameters with volatile if they may be changed during the execution of a function?