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
Program optimization
(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!
==Macros== Optimization during code development using [[Macro (computer science)|macros]] takes on different forms in different languages. In some procedural languages, such as [[C (programming language)|C]] and [[C++]], macros are implemented using token substitution. Nowadays, [[inline function]]s can be used as a [[type safe]] alternative in many cases. In both cases, the inlined function body can then undergo further compile-time optimizations by the compiler, including [[constant folding]], which may move some computations to compile time. In many [[functional programming]] languages, macros are implemented using parse-time substitution of parse trees/abstract syntax trees, which it is claimed makes them safer to use. Since in many cases interpretation is used, that is one way to ensure that such computations are only performed at parse-time, and sometimes the only way. [[Lisp programming language|Lisp]] originated this style of macro,{{Citation needed|date=September 2008}} and such macros are often called "Lisp-like macros". A similar effect can be achieved by using [[template metaprogramming]] in [[C++]]. In both cases, work is moved to compile-time. The difference between [[C (programming language)|C]] macros on one side, and Lisp-like macros and [[C++]] [[template metaprogramming]] on the other side, is that the latter tools allow performing arbitrary computations at compile-time/parse-time, while expansion of [[C (programming language)|C]] macros does not perform any computation, and relies on the optimizer ability to perform it. Additionally, [[C (programming language)|C]] macros do not directly support [[recursion (computer science)|recursion]] or [[iteration]], so are not [[Turing complete]]. As with any optimization, however, it is often difficult to predict where such tools will have the most impact before a project is complete.
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)