Thread: dynamic function calls

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    dynamic function calls

    I was wondering if it is possible to dynamically call a function at run-time without the program knowing what the function is or how many arguments or what type thae args are.
    (E.g.
    func (args);
    )

  2. #2
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Off the top of my head, you can dynamically call a function at run-time by using function pointers. However, I don't think you do that without knowing the "signature" of the function -- i.e. how many args and what they are.

    You might be able to do something va_arg lists, in your various fucntions, but I've never tried it.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Location
    Sydney
    Posts
    60
    If it's a function you're writing, you can write it to accept a variable number of arguments and use function pointers as fgw_three said, but I don't think it's possible if it's some arbitrary function - it has to be able to accept variable arguments.

  4. #4
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    I second what the other responders have said.

    It is possible to create a call at runtime if you have an intimate knowlege of the function linkage and are willing to use assembly language to do it. It is unlikely that you can do it with pure C code, and whatever it is will not be portable to other environments. Most source level debuggers have this capability, but they use platform specific code (most often in assembly code) to implement it.
    Insert obnoxious but pithy remark here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM