ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the Difference between macros and inline functions?

user-image
تم إضافة السؤال من قبل Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company
تاريخ النشر: 2014/11/23
Garima Gupta
من قبل Garima Gupta , Training , Training offered by Spoken Tutorial Project, IIT Bombay

Every time a function is called it takes a lot of extra time in executing a series of instructions for tasks such as jumping to the function, saving registers, pushing arguments into stack and returning to the calling function.

 

Solution to this problem is:

A) Macro

the drawback with macro is that they are not really functions and therefore, the usual error checking does not occur during compilation.To define preprocessor macros we can use #define. Its syntax is:

#define identifier replacement

When the preprocessor encounters this directive, it replaces any occurrence of identifier in the rest of the code byreplacement. This replacement can be an expression, a statement, a block or simply anything. 

 

B) Inline function

it is a function that is expanded in line when it is invoked. That is, the compiler replaces the function call with the corresponding function code. All inline functions must be defined before they are called. The functions are made inline when they are small enough to be defined in one or two lines.

The inline functions are defined as:

Inline function-header{

      function-body

}

Where Inline is a keyword.

For detail information can refer:  https://garimacoder.wordpress.com/2014/02/15/inline-functions-in-c

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟