querry regarding function pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lalatendu Das

    #1

    querry regarding function pointer

    hi
    Please someone give a real time implimentation of a function pointer.
    where exactly we need a function pointer very much . if it is in terms
    of code i will be happy enough .
    thanks in advance

  • pemo

    #2
    Re: querry regarding function pointer

    Lalatendu Das wrote:[color=blue]
    > hi
    > Please someone give a real time implimentation of a function pointer.
    > where exactly we need a function pointer very much . if it is in terms
    > of code i will be happy enough .
    > thanks in advance[/color]

    #include <stdio.h>
    #include <signal.h>


    void sigterm_handler (int sig)
    {
    printf("Handlin g signal %d", sig);
    }


    int main(void)
    {
    signal(SIGTERM, sigterm_handler );

    raise(SIGTERM);

    return 0;
    }


    --
    ==============
    Not a pedant
    ==============


    Comment

    • Vladimir S. Oka

      #3
      Re: querry regarding function pointer

      Lalatendu Das wrote:[color=blue]
      > Please someone give a real time implimentation of a function pointer.[/color]

      I guess you mean "real world"...
      [color=blue]
      > where exactly we need a function pointer very much.[/color]

      It really depends on your application. Simulating polymorphism is one.
      [color=blue]
      > if it is in terms of code i will be happy enough.[/color]

      #include <math.h>
      #include <stdio.h>

      #define PI 3.14159

      double (*trig)(double) ;

      int main(void)
      {
      trig = sin;
      printf("sin(PI) = %f\n", (*trig)(PI/2.0));

      trig = cos;
      printf("cos(PI) = %f\n", (*trig)(PI/2.0));

      return 0;
      }

      --
      BR, Vladimir

      Comment

      • Richard Heathfield

        #4
        Re: querry regarding function pointer

        Lalatendu Das said:
        [color=blue]
        > hi
        > Please someone give a real time implimentation of a function pointer.
        > where exactly we need a function pointer very much . if it is in terms
        > of code i will be happy enough .[/color]

        You can find good examples on page 118 of "The C Programming Language", 2nd
        edition, by Kernighan and Ritchie, or on pages 146-147 of "C - A Reference
        Manual", 4th edition, by Harbison and Steele.


        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999

        email: rjh at above domain (but drop the www, obviously)

        Comment

        • Lalatendu Das

          #5
          Re: querry regarding function pointer

          thanks for all your answers .They are really good. But specifically
          from the point veiw of protocol stack developement is there any
          instance which make use of pointer very needy andbest as well

          Comment

          • osmium

            #6
            Re: querry regarding function pointer

            Yes, of course.


            Comment

            • Vladimir S. Oka

              #7
              Re: querry regarding function pointer

              On Thursday 16 March 2006 15:45, osmium opined (in
              <47tfhhFhbok3U1 @individual.net >):
              [color=blue]
              > Yes, of course.[/color]

              But if I tell him, I'll have to kill him.

              --
              BR, Vladimir

              It's amazing how much "mature wisdom" resembles being too tired.

              Comment

              • Vladimir S. Oka

                #8
                Re: querry regarding function pointer

                On Thursday 16 March 2006 15:24, Lalatendu Das opined (in
                <1142522690.763 220.112500@j33g 2000cwa.googleg roups.com>):
                [color=blue]
                > thanks for all your answers .They are really good. But specifically
                > from the point veiw of protocol stack developement is there any
                > instance which make use of pointer very needy andbest as well[/color]

                Quote context, otherwise your posts make little sense. For example, it's
                an accident that I know you mean "function pointers" not just any
                pointers. Read and heed: <http://cfaj.freeshell. org/google/>. This
                one <http://clc-wiki.net/wiki/Introduction_to _comp.lang.c> is also
                useful.

                Back to your question: yes, there is a perfectly good place for function
                pointers in protocol stack development.

                <OT>
                For example: programming a sequence of tasks for the DSP to perform in
                lower parts of protocol stack of a mobile phone.
                </OT>


                --
                BR, Vladimir

                Trust in Allah, but tie your camel.
                -- Arabian proverb

                Comment

                Working...