Sponsored Links

Interview Questions



INTERVIEW QUESTIONS COMPUTER HARDWARE EMBEDDED SYSTEMS DETAILS

Question: Advantages and disadvantages of using macro and inline functions?

Answer: Advantage: Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.

Disadvantage: Macros and inline functions increased the size of executable code.

Submitted by Naveen Rao ([email protected])

_____

Difference in inline functions and macro
1) Macro is expanded by preprocessor and inline function are expanded by compiler.
2) Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once.

More over inline functions are used to overcome the overhead of function calls. Macros are used to maintain the readbility and easy maintainence of the code.

Submitted by Pooja Agrawal ([email protected])

Category Embedded Systems Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.3) By 7662 users
Added on 1/21/2011
Views 75073
Rate it!

Question: Advantages and disadvantages of using macro and inline functions?

Answer:

Advantage: Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.

Disadvantage: Macros and inline functions increased the size of executable code.

Submitted by Naveen Rao ([email protected])

_____

Difference in inline functions and macro
1) Macro is expanded by preprocessor and inline function are expanded by compiler.
2) Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once.

More over inline functions are used to overcome the overhead of function calls. Macros are used to maintain the readbility and easy maintainence of the code.

Submitted by Pooja Agrawal ([email protected]) Source: CoolInterview.com


Inline Functions versus Macros

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. Source: CoolInterview.com

Answered by: juke1909 | Date: 7/27/2009 | Contact juke1909 Contact juke1909

macro:
these get expanded during preprossing whenver invoked by the code.
Disadvantage:
1. calling macro too many times in the code will increase the size of the code.
2. simple operation can be performed which does not increase the size of the code.
3. Few operations are unpredictable.
example:
#define SQA(x) (++x * ++x)

int main()
{
int a = 2;
SQA(++a);
}
inline:
processed during compilation.
compiler optimizes a inline function either as a function if the performance overhead in calling a function is less compared to macro implementation, OR, it is implemented as Macro itself.
This optimization makes inline more preferable than macro

Note:
if function called:
a. return address had to be moved to stack.
b. register content has to be moved to stack.
c. function arguments has to be moved to stack.
d. memory allocation for the new function execution in ram has to done.
e. program counter has to loaded with the new address.
Source: CoolInterview.com

Answered by: Murali Prasath | Date: 9/4/2009 | Contact Murali Prasath Contact Murali Prasath

Another difference is Inline functions check for the type of parameter passed, Macros don't check parameter type, you can pass strings to a macro that does some integer arithmetic.
little correction in pooja answer in point 2.
2) Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once.
Expression passed to inline functions are evaluated and result is passed as value, whereas expressions passed as argument to macros are expanded, and if passed

#define MAX(a, b) ((a < b) ? b : a)

int main( void)

{

cout << "Maximum of 10 and 20 is " << MAX("20", "10") << endl;

return 0;

} Source: CoolInterview.com

Answered by: Mujeeb | Date: 10/29/2009 | Contact Mujeeb Contact Mujeeb

In MACROS the code is literally copied into the location it was called from. So if the user passes a "double" instead of an "int" then problems could occur.

In INLINE functions, if this senerio happens the compiler will complain about incompatible types.

In MACRO --> you cannot make the macro return something which is not the result of the last expression invoked inside it.

In INLINE --> you can return any value by using keyword return();

In MACROS -- > debugging is tough (because they refer to the expanded code, rather than the code the programmer typed.)
INLINe --> debugging is easy Source: CoolInterview.com

Answered by: calvin | Date: 12/14/2009 | Contact calvin Contact calvin


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
Why cannot arrays be passed by values to functions?
View Answer
Can structures be passed to the functions by value?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Embedded Systems Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2024 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions