Domanda di colloquio di Broadcom

Can a variable be both const and volatile ?

Risposta di colloquio

Anonimo

8 ago 2011

const indicates that the program cannot modify the variable; volatile informs the compiler that the contents of a pointer/variable may be changeable external to the program (e.g., shared memory or mapped memory). There is therefore no conflict between these two, and a const volatile entity is a variable that will be reread on each access (in case an entity external to the program updated it), but the compiler will insist that the program contain not contain logic that modifies that variable.

4