23rd December 2005, 10:07 #1
Newbie level 4
diffrence between macros and inline function
what is the difference between macro and the inline functions.
26th December 2005, 09:00 #2
Junior Member level 3
macro's doesnt check for syntactical errors
for inline there is syntactical check .....
26th December 2005, 09:00
26th December 2005, 12:40 #3
Full Member level 5
Usage of macros is always replaced with actual code (i.e. they are always in lined) While its up to the compiler to decide whether to replace the inline function call to function code or keep it as function call. There are some guidelines to be followed to make sure that your inline function is replaced with its code but even after following those guidelines its not guaranteed.
26th December 2005, 12:40
12th January 2006, 07:49 #4
Full Member level 2
Although inline functions are similar to macros (because the function code is expanded at the point of the call at compile time), inline functions are parsed by the compiler, whereas macros are expanded by the preprocessor. As a result, there are several important differences:
* Inline functions follow all the protocols of type safety enforced on normal functions.
* Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
* Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.
12th January 2006, 07:49
Full Member level 4
macros dont make the part of Code Segment Memory, but inline functions are a part of code segment.
Macro Expansion is a preprosessing time activity and inline function resolution (whether to accept the request for Inline or not) is a compile time activity.
Advanced Member level 3
macros are used if timing is more important
while inline functions are used when memory usage is more important
A macro in computer science is an abstraction, whereby a certain textual pattern is replaced according to a defined set of rules. The interpreter or compiler automatically replaces the pattern when it is encountered. In compiled languages, macro-expansion always happens at compile-time. The tool which performs the expansion is sometimes called a macro-expander. The term macro is used in many similar contexts which are derived from the concept of macro-expansion, including keyboard macros and macro languages. In most situations, the use of the word "macro" implies expanding a small command or action into a larger set of instructions.
The purpose of macros is to either automate frequently-used sequences or enable a more powerful abstraction — but these are often the same thing.
In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to in-line expansion; that is, it suggests that the compiler insert the complete body of the function in every context where that function is used.
Newbie level 4
1. macros are processed by the preprocessor while inline functions are processed by the compiler.
2. macros are marginally faster
3. Arguments for inline functions are typed, therefore compiler can apply some type checking to that function calls.
Macro isn't type checked and does not evaluate arguments, but simply takes the string passed to the macro and replace each occurence of macro argument in the text of macro with actual string for that parameter. It may give you sometimes very surpising results.
19th September 2013, 10:12 #9
Newbie level 1
Re: what is the difference between macro and the inline function
Per this article:
inline vs macro
"Inline functions are parsed by the compiler, whereas macros are expanded by the C++ preprocessor."
It's also said that debugging macros is difficult.