Thread: Function mapping at run-time

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    Function mapping at run-time

    Guess the best way to explain what I need is through the code itself.

    Code:
    # include<stdio.h>
    int func(void);
    int pfunc(void);
    
    int pfunc()
    {
        int val;
        /* do some work */
        return val;
    }
    
    int func()
    {
        int ret;
        /* log the start of  event in a file with the time */
        ret = pfunc();
        /* log the end of event in a file with the time */
        return ret;
    }
    
    int func()
    {
        int ret;
        ret = pfunc();
        return ret;
    }
    
    int main()
    { 
         int ret;
         ret = func();
         printf(" return value = %d\n",ref);
         return 0;
    }
    The main function invokes the func routine. If the user wishes to log the event at which the func routine is called, he sets a global parameter at run-time. Depending on whether the parameter is set or not, the appropriate func routine must be invoked.
    Could someone help me out and suggest a way of doing it?
    In the middle of difficulty, lies opportunity

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    using if statement?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Code:
    if (globalVar)
    {
         ret = pfunc();
    }
    else
    {
         ret = func();
    }
    Yes?

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Why have two functions? It looks like you want to turn logging on and off. Inside pfunc(), check if logging is enabled at the beginning and end, and print the messages if it is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 04:33 AM