In all the examples given in earlier posts, you have seen that a macro is working somewhat like a function. Function, as you already know is used when we want to perform the same task again and again. Similarly,wherever we need to perform the same task, we can write the name of the macro like we do in a function. So when should we use a function and when a macro?
Which is better ?
1. When we define a macro in our program and use it many times,the macro is expanded that many times resulting in an increase in the program size. Contrary to this, if a function is called numerous number of times, it would take the same amount of space in the program.
2. When we have a function with arguments, passing values to it and getting the returned value, takes some time. This time is saved in macros since they have already been expanded and placed in the source code before compilation.
3. When the task to be performed is small and easy, we should use macros as it will make use of the memory resources quite well, but if the task is heavy and you need to perform it frequently we should make space for a function instead of a macro.
4. Macros make the program process fast, but the drawback is that they make the program large. Function, make the program smaller in size.
0 comments:
Post a Comment