[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


How the inline differe from macro in C

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)

Question by bikram_bhatt
Submitted on 2/17/2004
Related FAQ: comp.lang.c Answers to Frequently Asked Questions (FAQ List)
Rating: Rate this question: Vote
How the inline differe from macro in C


Answer by ambujbansal_cs
Submitted on 5/27/2004
Rating:  Rate this answer: Vote
inline function support valid type of the argument passed to the function.and inline function sends a request to make it inline,it is up to the compiler whether it makes the function inline or not; depending on the  better performance result.

 

Answer by manjudotg
Submitted on 5/26/2005
Rating: Not yet rated Rate this answer: Vote
Macros replace the string by replacement text
Which falls the miss conception

#define func(x) x*x

if the call is made as
int i;
func(++i)

Then it would be replaced by
++i*++i
Which gives the wrong results

But the inline function suits the best in such cases

inline func(int n)
{
return n*n;

}

 

Answer by vijay
Submitted on 6/28/2006
Rating: Not yet rated Rate this answer: Vote
1. macros are processed by the preprocessor while inline functions are processed by the compiler.

2. macros are marginally faster

3. The difference is in interpreting arguments. 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.

 

Answer by BHISMADEB PANDA
Submitted on 8/3/2006
Rating: Not yet rated Rate this answer: Vote
The major draback of macro is that  it is not really a function, so the usual error cheking does not occur during compilation.

But in c++ has a solution . C++ provides a keyword that is inline. an inline function is a function  expanded in line when it is invoked. A function work as inline when it is small.

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.