answersLogoWhite

0


Best Answer

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.
User Avatar

Wiki User

โˆ™ 2010-12-26 15:27:48
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar
Study guides
๐Ÿ““
See all Study Guides
โœ๏ธ
Create a Study Guide

Add your answer:

Earn +20 pts
Q: What is the difference between a macro and a function?
Write your answer...
Submit
Related questions

What is the difference between a micro processor and a macro processor?

What is the difference between a micro processor and a macro processor?


What are the difference between micro marketing environment and macro marketing environment?

Difference between micro and macro marketing


What is the difference between executing a macro and calling a macro?

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


What is the difference between macro and micro decomposers?

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.


What is the difference between macro and micro?

Macro is big micro is small.


What is the difference between mirco and macro?

mirco= small macro= large


Difference between macro and micro?

Macro is big micro is little


What is the difference between macro and micro neutrons?

macro is bigger than micro


What is the difference between micro and macro- evolution?

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.


Difference between function and objective function?

difference between function and objectives?


What is difference between macro processor and macro assembler?

Ask Stephen short...he knows all ;)


Micro to macro processes in an ecosystem?

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


Give the differences between micro and macro economics?

ten difference of micro economics macro economics


What is the difference between Marco and aperture?

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


Difference between micro hardness and macro hardness test?

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


What is the difference between macro- and microeconomics?

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


What is the difference between member function and normal function?

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


What is the difference between a macro burst and a micro burst?

nuguu


What is the difference between Fanuc CNc and Siemens CNC?

macro


Difference between macro molecules and micro molecules?

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


What is the difference between macros and sub routine?

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


In embedded systems perspective which is better to use. Macro or function?

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".


Example of fundamental difference between a polynomial function and an exponential function?

fundamental difference between a polynomial function and an exponential function?


What is the difference between a macro and micro digital camera lens?

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.


What is the difference between macro and define?

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.