Advantages of Macros


A list of the advantages of macros reads like the list of advantages for using procedures. The two mechanisms---procedure calls and macro expansion---are completely different. But the resulting effect is often similar.

Advantages of Macros

The above list is not complete, and most of the reasons overlap. The whole list can be summarized by saying that the advantage of macros is "modularity." Of course, "modularity" also summarizes the advantages of procedure calls, of objects, and of structured programming.


QUESTION 9:

A complicated operation has been implemented using about 1000 lines of code. The operation is expected to be used many times in a typical application program. The programmer proposes to turn the code into a macro and put it in a macro library. Is this a good idea?


ANSWERS:

  1. No---expanded source files using the macro will get too large.
  2. No---since the macro is large it should not be placed in a library.
  3. Yes--users will not want to see the details, so the modularity of a macro is a good idea.
  4. Yes--once it is in a library all programmers can use it.