CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Location
    Germany
    Posts
    487

    does the function exist?

    Hello!

    I want to use a Pointer-to-Function to switch between different functions inside our own proprietary operating system.

    What I want to archieve is, that without any change my code, my code is able to check whether a function with a known name exists or not.

    Do you have any idea how to manage this in plain C?
    Thanks!



    Example:
    I think about something like:

    a()
    {
    //do something
    }


    main()
    {
    ..
    void (*PtF) (void);

    if (exist(function a))
    {
    PtF = a;
    PtF();
    }
    ..
    }

  2. #2
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Set up a linked list of structures containing a string and a function pointer. Register every function in the list. To find out whether a function exist, traverse the list and check the names.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  3. #3
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    Thanks, Gabriel!

    I think I will have to use this solution, although it has a disadvantage:

    Doing this requires, that the application programmer has to think of the list. He has to program things that he does not need in this moment for his project. So the acceptance of my colleagues will not be too good.

    I do not think that there is any better solution.

    Again: Thanks!

    Marc

  4. #4
    Join Date
    Aug 2002
    Location
    VA, USA
    Posts
    137
    Maybe not what you want (and not very portable) but if your
    developing on a Windows platform and your functions are
    contianed in a DLL you can use GetProcAddress() to check
    for their existence.

    regards, willchop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured