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
Read Online Advanced Embedded Systems Job Interview Questions And Answers
Top Advanced Embedded Systems Questions
☺ | Tell me what is the difference between microprocessor and microcontroller? |
☺ | Do you know what is lst file? |
☺ | What is high-end embedded processor? |
☺ | What is interrupt latency? How can you reduce it? |
☺ | What is embedded system in a computer system? |
Top New Artificial Intelligence Categories
☺ | Virtual Assistant Interview Questions. |
☺ | Artificial Intelligence Robotics Interview Questions. |
☺ | AI Fuzzy Logic Interview Questions. |
☺ | Artificial Intelligence Neural Networks Interview Questions. |
☺ | Artificial Intelligence Games Interview Questions. |