Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews New Artificial Intelligence Interviews:Advanced Embedded SystemsAI Fuzzy LogicAI GeneralAI Knowledge RepresentationAI LanguagesAI RecognitionArtificial Intelligence GamesArtificial Intelligence Language ProcessingArtificial Intelligence Neural NetworksArtificial Intelligence RoboticsArtificial Intelligence ToolsVirtual AssistantVirtual Reality
Copyright © 2018. All Rights Reserved
Advanced Embedded Systems Interview Question:
Explain me how are macros different from inline functions?
Submitted by: Muhammad☛ Macros are normally used whenever a set of instructions/tasks have to be repeatedly performed. They are small programs to carryout some predefined actions.
☛ We normally use the #define directive in case we need to define the values of some constants so in case a change is needed only the value can be changed and is reflected throughout.
#define mul(a,b) (a*b)
☛ The major disadvantage of macros is that they are not really functions and the usual error checking and stepping through of the code does not occur.
☛ Inline functions are expanded whenever it is invoked rather than the control going to the place where the function is defined and avoids all the activities such as saving the return address when a jump is performed. Saves time in case of short codes.
inline float add(float a,float b)
{
return a+b;
}
☛ Inline is just a request to the compiler and it is upto to the compiler whether to substitute the code at the place of invocation or perform a jump based on its performance algorithms.
Submitted by: Muhammad
☛ We normally use the #define directive in case we need to define the values of some constants so in case a change is needed only the value can be changed and is reflected throughout.
#define mul(a,b) (a*b)
☛ The major disadvantage of macros is that they are not really functions and the usual error checking and stepping through of the code does not occur.
☛ Inline functions are expanded whenever it is invoked rather than the control going to the place where the function is defined and avoids all the activities such as saving the return address when a jump is performed. Saves time in case of short codes.
inline float add(float a,float b)
{
return a+b;
}
☛ Inline is just a request to the compiler and it is upto to the compiler whether to substitute the code at the place of invocation or perform a jump based on its performance algorithms.
Submitted by: Muhammad
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.