Difference between Macro And function


In C (and C++) a macro is a preprocessor directive. This means that before your program starts compiling it will go through and process all your macros. Macros are useful because
  • They can make your program easier to read
  • They can improve efficiency (as they can be calculated at compile time)
  • They can shorten long or complicated expressions that are used a lot. 
Disadvantages:
  • Expand the size of your executable
  • Can flood your name space if not careful. For example, if you have too many preprocessor macros you can accidentally use their names in your code, which can be very confusing to debug.
The compilation and execution process of C can be divided in to multiple steps:
  • Preprocessing - Using a Preprocessor program to convert C source code in expanded source code. "#includes" and "#defines" statements will be processed and replaced actually source codes in this step.
  • Compilation - Using a Compiler program to convert C expanded source to assembly source code.
  • Assembly - Using a Assembler program to convert assembly source code to object code.
  • Linking - Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
  • Loading - Using a Loader program to load the executable code into CPU for execution.

Comments

Popular posts from this blog

Three mislabeled Jar