Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What's the meaning of marking a whole class volatile?

What's the meaning of marking a whole class volatile?

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 4 Posters 955 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PikaCat
    wrote on last edited by
    #1
    #include <iostream>
    volatile class A{
    public:
        void func1();
        void func2();
        void func3();
    };
    int main(){
        return 0;
    }
    

    Is there any difference between a non-volatile class and a volatile class?

    kshegunovK 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Its kinda compiler dependant and also change a bit with c++ 11. ( to mean hardware access related)
      Basically it tells the compiler it should not include the class/type in certain optimizations and
      caching strategies.
      That said, in 30 years of programming I have never used or seen a
      volatile class in production code.
      Only in cases with a misunderstanding of the keyword and used in inter-thread communication.

      1 Reply Last reply
      2
      • P PikaCat
        #include <iostream>
        volatile class A{
        public:
            void func1();
            void func2();
            void func3();
        };
        int main(){
            return 0;
        }
        

        Is there any difference between a non-volatile class and a volatile class?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        I'm not aware of a volatile class. You can have volatile functions and volatile objects, but that specifier makes no sense for classes ...

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          yeah, I tend to think of volatile as a modifier for variables and not classes. Often ask in interviews whether the candidate knows what its for in embedded systems. Often misused, but important to understand the implications and when they are desirable: memory mapped register manipulation, etc.

          If you meet the AI on the road, kill it.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved