how can I find the addres of function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashu singhh
    New Member
    • Oct 2012
    • 1

    how can I find the addres of function

    mail the ans on (email removed)
    Last edited by Rabbit; Oct 14 '12, 04:35 PM. Reason: Email has been removed per forum policy.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The name of a function is the address of the function.

    You can just typecast the functon name to an int.

    Comment

    • Shubhangi24
      New Member
      • Oct 2012
      • 20

      #3
      Can you plz tell me how to do that?

      Comment

      • Shubhangi24
        New Member
        • Oct 2012
        • 20

        #4
        @ashu, If you write following code you will get address of function.

        Code:
        void display();
        int main()
        {
           	printf("address:=%u",&display);
        	return 0;
        }
        void display()
        {
         printf("Hello");
        }
        Last edited by Meetee; Oct 15 '12, 06:53 AM. Reason: code tags <code/> added

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          An int may not be large enough to hold an address. I suggest you use a long int.
          Code:
          long addr = &display;
          printf("address:=%lu\n",addr);
          However, be aware that you are stepping into the realm of implementation-defined or undefined behavior. The Standard does not require a compiler to provide any integral types that can hold the value of a function pointer. In fact, a compiler is not required to provide a single pointer type that can hold both pointer-to-data and pointer-to-function.

          Comment

          Working...