Search code examples
cvolatile

volatile keyword in C, are all variables marked as volatile?


Sorry if I am asking a stupid question, but I can't find the answer due to clumsy search terms I guess

If I declare three variables as follows

volatile uint16_t a, b, c;

Will all three variables be declared volatile?

Or should I really not declare multiple variables in a row but instead do:

volatile uint16_t a;
volatile uint16_t b;
volatile uint16_t c;

Solution

  • If I declare three variables as follows

    volatile uint16_t a, b, c;
    

    Will all three variables be declared volatile?

    Yes, all 3 variables will be volatile.

    Or should I really not declare multiple variables in a row but instead do:

    That is related to code style and personal preference. Usually declaring variables one per line is preferred, is more readable, easier to read, easier to refactor and results in more readable changes when browsing diff output of files.