Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
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.
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.
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.
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.
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.