Need better understanding about Type Qualifiers

It appears that there is no explanation about type qualifiers. I did some surfing and found out that there are 3 type qualifiers, that are : const, volatile, and restrict. May someone explain about these and when to use them?

Thanks in advance.
const: value cannot be changed (without some hacks). Compiler is able to generate more efficient code on this assumption (for example replace compile-tyme constants with it's values). Also you are less likely to accidently change what doen't meant to change (protect you from errors)

volatile: this variable can be changed by OS, another thread or memory-mapped device, so compiler cannot optimize away any operatopns with it: ++x; --x; would be probably optimized away (as state of x is the same before and after those operations) but if x is volatile it cannot do that (as x can be read between them).

restrict: not part of C++. In C99 it promises that only restricted pointer will access object it points to. Allows more optimizations
Last edited on
I guess they're not so important, but at least I know what it does. Thanks for all of your answers. I really appreciate it.
> I guess they're not so important

const is very very important.

yeah const is useful and important. I forgot to mention that.
Last edited on
Topic archived. No new replies allowed.