C Programming
Algebra
The Difference Between

What is the difference between a macro and a function?

484950

Top Answer
User Avatar
Wiki User
Answered
2010-12-26 15:27:48
2010-12-26 15:27:48

Macros are essentially shorthand representations of arbitrary sections of the source code, which makes the source code succinct, while its (the macro template's) expansion replaces each of its presence prior to compilation. Whatever is there to do with Macros, it is done by the preprocessor, so that the source code is ready for compilation. Function is a calling routine, whence a large program is divided into separate portions, each portion doing a separate job, and proper calling of these portions in different places combines the works done by them into the required complete output. Thus functions have nothing to do with the preprocessing period, they are just compiled. To some extent function and macro is similar, for a macro can occasionally be invoked to perform a task that is generally entrusted to a function. But the similarity ends there.

The differences are:
  1. Macro consumes less time. When a function is called, arguments have to be passed to it, those arguments are accepted by corresponding dummy variables in the function, they are processed, and finally the function returns a value that is assigned to a variable (except for a void function). If a function is invoked a number of times, the times add up, and compilation is delayed. On the other hand, the macro expansion had already taken place and replaced each occurrence of the macro in the source code before the source code starts compiling, so it requires no additional time to execute.
  2. Function consumes less memory. While a function replete with macros may look succinct on surface, prior to compilation, all the macro-presences are replaced by their corresponding macro expansions, which consumes considerable memory. On the other hand, even if a function is invoked 100 times, it still occupies the same space. Hence function is more amenable to less memory requirements.
234
๐ŸŽƒ
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Related Questions




Calling a macro loads the macro into memory, while executing the macro runs the macro.



Macro is big micro is little




The difference between macro and micro decomposers is micro decomposers can't be seen by the naked eye while macro decomposers are big enough so they can be seen.


difference between function and objectives?



The difference between micro and macro evolution is that micro evolution does not involve creation any new allele while macro evolution involves creation of the new alleles.


A function is more difficult than a relation while a relation is more simpler than a function.


ten difference of micro economics macro economics


t s the difference between micro and macro process in the ecosystem?


The same as the difference between huoses and oranges. Did you mean "macro" instead of "marco"?


micro is on a small scale and macro on a larger scale


In VBA, a macro is the name for the function that you can see on the GUI and use, and a function is a procedure called by a macro. A Macro is more "on the stage", and a Function is more "backstage".


What is the difference between malloc() and calloc()?


A macro is the entire section of code, while a sub-routine is part of the macro.


the molecules required by our body in small quantity is kown as macro molecules


macro- and microeconomics courses (the "big picture" versus individual companies/persons)


fundamental difference between a polynomial function and an exponential function?


On SLRs, macro lenses are specially corrected for extreme close-up work. Nikon brand macro lenses bear the name 'Micro', so there is really not much difference.


A macro is simply a text-substitution mechanism. You use the #define directive to define both macro symbols and precompiler directives. Every occurrence of a macro symbol within your code is substituted with the macro definition during preprocessing.


Macro refers to something large in scale, scope or capability; micro, is the opposite, and refers to something small



Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.