Function mapping at run-time

This is a discussion on Function mapping at run-time within the C Programming forums, part of the General Programming Boards category; Guess the best way to explain what I need is through the code itself. Code: # include<stdio.h> int func(void); int ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    using if statement?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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, 12:03 PM
  5. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 03:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21