Thread: What are the benefits of using macro functions over regular functions

  1. #1
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    137

    Question What are the benefits of using macro functions over regular functions

    I've been working with a codebase in which the developer has interspersed a lot of macro functions in with standard functions in C. I would like to know the main pros of why a programmer would use a macro function over a standard function because looking at the code, I cannot really tell why the programmer chose macro functions over standard functions and would like to get more educated with this. Thnak you.
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    • If you needed to simulate a generic function (e.g., the kind that might be done with a function template in C++) and using void pointers was not desired, you might consider a function-style macro since types can be passed as arguments to function-style macros.
    • In the absence of inline function support, you might define a function-style macro to manually inline code.
    • Sometimes a macro could be used to reduce repeated writing of boilerplate code.
    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
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    137
    Ahh thank you laserlight!
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-27-2013, 06:43 PM
  2. accessing static functions in header via macro
    By wirmius in forum C Programming
    Replies: 1
    Last Post: 05-11-2013, 06:52 AM
  3. macro functions/efficiency tricks (old-style?)
    By jsaetrum in forum C Programming
    Replies: 8
    Last Post: 01-05-2012, 02:19 PM
  4. macro functions console appi
    By In_Control001 in forum C Programming
    Replies: 2
    Last Post: 02-17-2010, 03:22 PM
  5. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 07:05 PM

Tags for this Thread