Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Advantages and disadvantages of using macro and inline functions?

0
Posted

Advantages and disadvantages of using macro and inline functions?

0

A macro is a constant that provides straight textual substitution where used, while an inline function is a procedure that is actually called each time. Macros do have a few advantages over inline functions, but the disadvantages are numerous. For example, type checking and argument validation is not performed in a macro, while they are in functions for the most part. It is a matter that everyone should decide for themselves, but Bjarne Stroustrup, who created C++, advocates the use of inline functions over macros. Inline functions are an imperative feature of C++ and are frequently used with classes. These are no different from the normal functions except for the fact that they are never actually called. These functions are, as their name suggests, expanded in line at each point of invocation. All that needs to be done to enable or cause a function to expand at the point of invocation is to add the inline keyword before the function definition.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123