Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Macro (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Parameterized and parameterless macro{{anchor|Parameterized macro|Parameterized|Parameterless}}== A '''parameterized macro''' is a macro that is able to insert given objects into its expansion. This gives the macro some of the power of a [[function (computer science)|function]]. As a simple example, in the [[C (programming language)|C programming language]], this is a typical macro that is ''not'' a parameterized macro, i.e., a '''parameterless macro''': '''#define''' PI 3.14159 This causes <code>PI</code> to always be replaced with <code>3.14159</code> wherever it occurs. 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 (computer science)|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 [[inline expansion|in-line expansion]], but in languages such as [[C (programming language)|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 function]]s. The parameterized macros used in languages such as [[Lisp programming language|Lisp]], [[PL/I]] and [[Scheme (programming language)|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]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)