Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

what is the difference between macro and the inline function

Status
Not open for further replies.

phanikumar

Newbie level 4
Joined
Oct 27, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
diffrence between macros and inline function

hi

what is the difference between macro and the inline functions.
 

Re: c

macro's doesnt check for syntactical errors
for inline there is syntactical check .....
 

c

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.
 

c

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.
 

Re: c

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.
 

Re: c

macros are used if timing is more important
while inline functions are used when memory usage is more important
 

c

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.
 

Re: c

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.
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top