Parameterized macro

Parameterized macro

In computer science, a parameterized macro is a type of macro that is able to insert given objects into its expansion. This gives the macro some of the power of a function.

As a simple example, in the C programming language, this is a typical macro that is "not" a parameterized macro: #define PI 3.14159This causes the string "PI" to be replaced with "3.14159" wherever it occurs. It will always be replaced by this string, and the resulting string cannot be modified in any way. An example of a parameterized macro, on the other hand, is this: #define pred(x) ((x)-1)What this macro expands to depends on what argument "x" is passed to it. Here are some possible expansions: pred(2) → ((2) -1) pred(y+2) → ((y+2) -1) pred(f(5)) → ((f(5))-1)Parameterized macros are a useful source-level mechanism for performing in-line expansion, but in languages such as C where they use simple textual substitution, they have a number of severe disadvantages over other mechanisms for performing in-line expansion, such as inline functions.

The parameterized macros used in languages such as Lisp, PL/I and Scheme, on the other hand, are much more powerful, able to make decisions about what code to produce based on their arguments; thus, they can effectively be used to perform run-time code generation.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Inline function — In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to in line expansion; that is, it suggests that the compiler insert the complete body of the… …   Wikipedia

  • Generic programming — is a style of computer programming in which algorithms are written in terms of to be specified later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983. This… …   Wikipedia

  • Microsoft Access — Microsoft Office Access 2010 running on Windows 7 Developer(s) Microsoft Corporation …   Wikipedia

  • C preprocessor — The C preprocessor (cpp) is the preprocessor for the C and C++ computer programming languages. The preprocessor handles directives for source file inclusion (#include), macro definitions (#define), and conditional inclusion (#if). In many C… …   Wikipedia

  • List of programming languages by category — Programming language lists Alphabetical Categorical Chronological Generational This is a list of programming languages grouped by category. Some languages are listed in multiple categories. Contents …   Wikipedia

  • ISO 10303 Application Modules — The STEP Application modules define common building blocks to create modular Application Protocols (AP) within ISO 10303. Higher level modules are built up from lower level modules. The modules on the lowest level are wrappers of concepts,… …   Wikipedia

  • SystemVerilog — In the semiconductor and electronic design industry, SystemVerilog is a combined Hardware Description Language and Hardware Verification Language based on extensions to Verilog. SystemVerilog was created by the donation of the Superlog language… …   Wikipedia

  • Compiler optimization — is the process of tuning the output of a compiler to minimize or maximize some attributes of an executable computer program. The most common requirement is to minimize the time taken to execute a program; a less common one is to minimize the… …   Wikipedia

  • Inline expansion — In computing, inline expansion, or inlining, is a manual or compiler optimization that replaces a function call site with the body of the callee. This optimization may improve time and space usage at runtime, at the possible cost of increasing… …   Wikipedia

  • Simucad — Infobox Company company name = Simucad Design Automation, Inc. company company type = Private Company| foundation = 2004 location = key people = Dr Ivan Pesic, President/CEO Mr Marc Goldberg, Sales Contact industry = Software Programming homepage …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”