DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    imran Guest

    calling functions using pointers


    hi,

    i was once told that you can call a function using a pointer to that function.
    can anyone help me understand how it works? thanx.

    imran.

  2. #2
    MSDN Guest

    Re: calling functions using pointers


    "imran" <00030026@lums.edu.pk> wrote:
    >
    >hi,
    >
    >i was once told that you can call a function using a pointer to that function.
    >can anyone help me understand how it works? thanx.
    >
    >imran.


    From MSDN

    #include <stdio.h>

    typedef int (*myintchartype) (char *, char *);
    typedef void (*myvoidtype) (void);
    typedef int (*myintvoidtype) (void);

    int func1(char *, char *);
    void func2(void);

    void main(void)
    {
    myintvoidtype ptr;

    ptr = (myintvoidtype) func1;
    ((myintchartype) ptr)("one", "two");

    ptr = (myintvoidtype) func2;
    ((myvoidtype) ptr)();
    }

    int func1(char *a, char *b)
    {
    return printf("func1 took two parameters: %s and %s\n", a, b);
    }

    void func2(void)
    {
    printf("func2 did not take any parameters\n");
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links