volatile and pointer functions

Discussion in 'C Programming' started by venky, Aug 10, 2006.

  1. venky

    venky Guest

    Hi all,

    I'm new to group n c. i want to know in detail about volatile qualifier
    and pointer to functions with examples.

    thank you
     
    venky, Aug 10, 2006
    #1
    1. Advertising

  2. venky

    manmohan Guest

    venky wrote:
    > Hi all,
    >
    > I'm new to group n c. i want to know in detail about volatile qualifier
    > and pointer to functions with examples.
    >
    > thank you


    For a better and exhaustive explanation look through
    http://www.c-faq.com

    The keyword volatile allow you to declare variables (or pointers
    to data) which you promise not to change, (or which might change in
    unexpected ways behind the program's back.) A nice example would be
    some variable in your routine, which is to be accessed by the
    clock-routine of the system and constantly updated.This variable is not
    supposed to be accessed or modified in scopes internal to your
    program;rather is done externally!!

    Regarding pointers to functions too look through same link!!
    I would recommend you to go through Clockwise/spiral Rule of
    complicated declarations and working of "cdecl".

    Hope it helps!!
     
    manmohan, Aug 10, 2006
    #2
    1. Advertising

  3. venky

    Guest

    hi
    in simple the volatile keyword tells the compiler to leave the
    variable alone.. and not to agressively optimise it ...
    the variable may be used in memory mapped io shared memory
    implementation etc...
    a simple way to understand this would be to do the following


    int main ()
    {
    int x ;
    volatile int y ;
    x = 1 ;
    x= 1 ;
    x= 1 ;
    y = 1 ;
    y = 1 ;
    y =1 ;
    }

    compile this code with optimiser int a .s file using
    cc -S -o prog.c

    view the prog.s file..
    you will see that for x .. the compiler ignores the repeated
    commands.. but it faithfully executes all the redundant commands for
    the var y...
    regards
    rahul


    w
    manmohan wrote:

    > venky wrote:
    > > Hi all,
    > >
    > > I'm new to group n c. i want to know in detail about volatile qualifier
    > > and pointer to functions with examples.
    > >
    > > thank you

    >
    > For a better and exhaustive explanation look through
    > http://www.c-faq.com
    >
    > The keyword volatile allow you to declare variables (or pointers
    > to data) which you promise not to change, (or which might change in
    > unexpected ways behind the program's back.) A nice example would be
    > some variable in your routine, which is to be accessed by the
    > clock-routine of the system and constantly updated.This variable is not
    > supposed to be accessed or modified in scopes internal to your
    > program;rather is done externally!!
    >
    > Regarding pointers to functions too look through same link!!
    > I would recommend you to go through Clockwise/spiral Rule of
    > complicated declarations and working of "cdecl".
    >
    > Hope it helps!!
     
    , Aug 10, 2006
    #3
  4. venky

    Guest

    hi
    in simple the volatile keyword tells the compiler to leave the
    variable alone.. and not to agressively optimise it ...
    the variable may be used in memory mapped io shared memory
    implementation etc...
    a simple way to understand this would be to do the following


    int main ()
    {
    int x ;
    volatile int y ;
    x = 1 ;
    x= 1 ;
    x= 1 ;
    y = 1 ;
    y = 1 ;
    y =1 ;
    }

    compile this code with optimiser int a .s file using
    cc -S -o prog.c

    view the prog.s file..
    you will see that for x .. the compiler ignores the repeated
    commands.. but it faithfully executes all the redundant commands for
    the var y...
    regards
    rahul


    w
    manmohan wrote:

    > venky wrote:
    > > Hi all,
    > >
    > > I'm new to group n c. i want to know in detail about volatile qualifier
    > > and pointer to functions with examples.
    > >
    > > thank you

    >
    > For a better and exhaustive explanation look through
    > http://www.c-faq.com
    >
    > The keyword volatile allow you to declare variables (or pointers
    > to data) which you promise not to change, (or which might change in
    > unexpected ways behind the program's back.) A nice example would be
    > some variable in your routine, which is to be accessed by the
    > clock-routine of the system and constantly updated.This variable is not
    > supposed to be accessed or modified in scopes internal to your
    > program;rather is done externally!!
    >
    > Regarding pointers to functions too look through same link!!
    > I would recommend you to go through Clockwise/spiral Rule of
    > complicated declarations and working of "cdecl".
    >
    > Hope it helps!!
     
    , Aug 10, 2006
    #4
  5. venky

    Chris Dollin Guest

    venky wrote:

    > I'm new to group n c. i want to know in detail about volatile qualifier


    Why?

    > and pointer to functions with examples.


    Why?

    I ask because it's much easier to provide useful answers if we know the
    context of the question.

    --
    Chris "seeker" Dollin
    "Who do you serve, and who do you trust?" /Crusade/
     
    Chris Dollin, Aug 10, 2006
    #5
  6. "venky" <> writes:
    > I'm new to group n c. i want to know in detail about volatile qualifier
    > and pointer to functions with examples.


    Read a good C textbook.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 10, 2006
    #6
  7. venky

    Thad Smith Guest

    wrote:

    > in simple the volatile keyword tells the compiler to leave the
    > variable alone.. and not to agressively optimise it ...


    More explicitly, it specifies that each access of the variable must be
    performed as written between the enclosing sequence points and not at
    any other times. What constitutes an access is implementation-defined.

    --
    Thad
     
    Thad Smith, Aug 11, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ben
    Replies:
    5
    Views:
    616
    Ulrich Eckhardt
    Jan 11, 2005
  2. Rakesh Kumar
    Replies:
    15
    Views:
    1,174
    Pete Becker
    Dec 31, 2007
  3. Tristan Wibberley
    Replies:
    0
    Views:
    421
    Tristan Wibberley
    Dec 31, 2007
  4. Tristan Wibberley
    Replies:
    3
    Views:
    406
    Tristan Wibberley
    Jan 1, 2008
  5. Stephen Howe
    Replies:
    2
    Views:
    303
    Stephen Howe
    Nov 6, 2012
Loading...

Share This Page