A procedure, also sometimes called a function, routine or subroutine, is a section of code that performs a certain task which is used repeatedly within an application. For example, a procedure might sort the names in a list of names alphabetically. An application may hold a list of names of countries, cities, and people, and may be designed to use the same procedure to sort all three lists of names. It is characteristic for a procedure that the procedure's code exists once within the application. Executing the procedure requires that the processor "jumps" to the procedure and, upon completion, returns to the location following the "jump." Because this "jump" supports the means to return from the procedure, it is typically called a call, but terminology varies.
A macro typically contains a smaller section of code. Just like with a procedure, the macro supports a notion of "write once, use more than once." Unlike a procedure, however, a main thread of execution does not call the code and return from it. Instead, the macro inserts its code into the main code, and this expands into as many location as it is used.
For example, a macro could be a simple expression to obtain the number of names in the list of names. In this hypothetical example, this is is easily obtained and doesn't justify the overhead of call and return, and the application may benefit from the higher execution speed (at the price of an increased memory footprint).
Chat with our AI personalities