Welcome to EDAboard.com

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.

Register Log in

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.
 

raja.bhavanam

Junior Member level 3
Joined
Nov 22, 2005
Messages
28
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,502
Re: c

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

dipal_z

Full Member level 5
Joined
Apr 21, 2005
Messages
278
Helped
37
Reputation
74
Reaction score
7
Trophy points
1,298
Location
India
Activity points
3,008
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.
 

sinu_gowde

Full Member level 2
Joined
Nov 10, 2005
Messages
137
Helped
32
Reputation
64
Reaction score
12
Trophy points
1,298
Activity points
3,490
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.
 

ivar4ever

Full Member level 3
Joined
Jun 12, 2006
Messages
189
Helped
25
Reputation
52
Reaction score
5
Trophy points
1,298
Location
India
Activity points
2,441
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.
 

salma ali bakr

Advanced Member level 3
Joined
Jan 27, 2006
Messages
971
Helped
104
Reputation
206
Reaction score
21
Trophy points
1,298
Activity points
7,491
Re: c

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

jjohn

Banned
Joined
Jun 17, 2006
Messages
158
Helped
17
Reputation
34
Reaction score
8
Trophy points
1,298
Activity points
0
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.
 

webmegamaster

Newbie level 4
Joined
Nov 17, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,325
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.
 

Joseph Porter

Newbie level 1
Joined
Sep 19, 2013
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
5
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top