Thread: Function overloading

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    72

    Function overloading

    Hi everyone,

    I found a library that defines a preprocessor function style like this:

    Code:
    #define_EXFUN(name, proto)     name proto
    and then declare the functions like this:

    Code:
    clock_t    _EXFUN(clock,    (void));
    double     _EXFUN(difftime, (time_t _time2, time_t _time1));
    time_t     _EXFUN(mktime,   (struct tm *_timeptr));
    time_t     _EXFUN(time,     (time_t *_timer));
    
    What is the purpose of the preprocessor style function? I mean it could just be ommited and declare the function like this right?

    Code:
    clock_t    clock(void);
    double     difftime(time_t _time2, time_t _time1);
    time_t     mktime(struct tm *_timeptr);
    time_t     time(time_t *_timer);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,351
    Were you looking at a standard library implementation? Is there an alternative definition of the _EXFUN macro depending on say, a #if preprocessor directive?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    72
    Yes your're right..

    Function overloading-screenshot_2-png
    Last edited by Nikosant03; 01-29-2021 at 06:12 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,351
    You'll need to fix that link.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,351
    Well, then you have your answer: it is to adjust the function declaration based on a preprocessor definition.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    72
    Yes, thanks for the quick tip!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function overloading, why is it done?
    By badger7755 in forum C# Programming
    Replies: 6
    Last Post: 12-10-2016, 04:58 AM
  2. C Function Overloading
    By amayes in forum C Programming
    Replies: 1
    Last Post: 10-30-2015, 12:23 AM
  3. Function overloading
    By saikumar029 in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2010, 11:43 AM
  4. Function Overloading
    By vb.bajpai in forum C++ Programming
    Replies: 8
    Last Post: 06-21-2007, 01:29 PM
  5. function overloading
    By lilhawk2892 in forum C++ Programming
    Replies: 5
    Last Post: 09-16-2006, 12:45 PM

Tags for this Thread