Thread: embedded c code and volatile question

  1. #1
    Registered User
    Join Date
    Mar 2020

    embedded c code and volatile question

    Good afternoon....
    I have a global int defined....It gets incremented in firmware (i++) each time an MSP430 wakes up and jumps into a GPIO Interrupt. Can someone tell me if I should have "volatile" modifier on it? I am always confused about this....Technically the ISR is a hardware piece however the act of the integer changing is NOT tied to anything other than the firmware incrementing it.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You should probably have the volatile modifier, since from your description it appears that the variable is being changed asynchronously to your program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2020
    Thank you.....Never heard the word asynchronously used with volatile but that I understand that...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about volatile
    By homer_3 in forum C++ Programming
    Replies: 26
    Last Post: 12-20-2014, 09:06 AM
  2. embedded c code on c compiler
    By vinayharitsakp@ in forum C Programming
    Replies: 8
    Last Post: 11-28-2007, 03:31 AM
  3. fork volatile question
    By rotis23 in forum Linux Programming
    Replies: 2
    Last Post: 04-07-2004, 07:31 AM
  4. Trace Embedded Code
    By SpEkTrE in forum C Programming
    Replies: 1
    Last Post: 10-13-2003, 01:37 PM
  5. C compiler that will compile C code with embedded sql
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-18-2002, 09:59 AM

Tags for this Thread