Thread: Doubt regarding the volatile keyword

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    3

    Doubt regarding the volatile keyword

    What i understood is
    (1)volatile unsigned char * ADC_address;
    ---ADC_address is a pointer which stores a volatile unsigned character .

    (2)volatile unsigned int ADC_voltage = 0;
    ---ADC_voltage is volatile unsigned integer variable ,

    (3)volatile unsigned char * ADC_REAL_ADDRESS;
    ADC_REAL_ADDRESS = (volatile unsigned char *)STA_MEMORY_BASE;
    ---Typecasting STA_MEMORY_BASE to volatile unsigned char pointer and assigned to ADC_REAL_ADDRESS.

    If I wrong means please correct me.

    What i don't understood is
    (4)Can anyone explain the below statements
    #define PINSEL_BASE_ADDR 0xE002C000
    #define PINSEL0 (*(volatile unsigned long *)(PINSEL_BASE_ADDR + 0x00))

    what I understood is (volatile unsigned long *)(PINSEL_BASE_ADDR + 0x00) in this statement (PINSEL_BASE_ADDR + 0x00) is type casted to volatile unsigned long pointer. But (*(volatile unsigned long *)(PINSEL_BASE_ADDR + 0x00)) , what is for the starting star(dereferencing operator) after first bracket.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Your first three points are correct.

    Quote Originally Posted by 2001goran View Post
    (*(volatile unsigned long *)(PINSEL_BASE_ADDR + 0x00)) , what is for the starting star(dereferencing operator) after first bracket.
    You already know what it is - it's the dereferencing operator. This statement is saying "take PINSEL_BASE_ADDR, cast it to be a volatile unsigned long pointer, and then dereference it to give the unsigned long located there". In other words, using "PINSEL0" in your code read the value at PINSEL_BASE_ADDR (i.e. at 0xE002C000).
    Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)

    ~~~

    "The largest-scale pattern in the history of Unix is this: when and where Unix has adhered most closely to open-source practices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline."

    Eric Raymond, The Art of Unix Programming

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To Volatile, or not to Volatile?
    By EVOEx in forum C++ Programming
    Replies: 16
    Last Post: 05-12-2012, 02:07 PM
  2. Volatile Variables
    By Gauravmore in forum C Programming
    Replies: 4
    Last Post: 01-11-2011, 08:29 AM
  3. Volatile Keyword!!
    By maven in forum C Programming
    Replies: 8
    Last Post: 12-06-2005, 12:56 PM
  4. volatile??
    By jacktibet in forum C Programming
    Replies: 2
    Last Post: 05-29-2003, 03:46 PM
  5. volatile keyword help!!!!
    By penney in forum Linux Programming
    Replies: 2
    Last Post: 03-12-2003, 08:09 AM