diff options
author | Björn Gustavsson <[email protected]> | 2018-05-17 14:10:58 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2018-05-17 14:10:58 +0200 |
commit | 52fe21127a1e2d82a0239e8e46467ad9b778677f (patch) | |
tree | 63e426f664f996774ac40a9273235b20674063b4 /system/doc | |
parent | b65538a9598981764b018e1cda409a36957a6ee7 (diff) | |
parent | 46237d41e7455ae5801d78e85a82216b73697f44 (diff) | |
download | otp-52fe21127a1e2d82a0239e8e46467ad9b778677f.tar.gz otp-52fe21127a1e2d82a0239e8e46467ad9b778677f.tar.bz2 otp-52fe21127a1e2d82a0239e8e46467ad9b778677f.zip |
Merge pull request #1810 from tomas-abrahamsson/bjorn/preprocessor-extensions
Add ?OTP_RELEASE, -if and -elif to the preprocessor
OTP-15087
Diffstat (limited to 'system/doc')
-rw-r--r-- | system/doc/reference_manual/macros.xml | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/system/doc/reference_manual/macros.xml b/system/doc/reference_manual/macros.xml index a341307ab7..760599308c 100644 --- a/system/doc/reference_manual/macros.xml +++ b/system/doc/reference_manual/macros.xml @@ -150,6 +150,11 @@ bar(X) -> <item>The name of the current function.</item> <tag><c>?FUNCTION_ARITY</c></tag> <item>The arity (number of arguments) for the current function.</item> + <tag><c>?OTP_RELEASE</c></tag> + <item>The OTP release that the currently executing ERTS + application is part of, as an integer. For details, see + <seealso marker="erts:erlang#system_info/1"><c>erlang:system_info(otp_release)</c></seealso>. + This macro was introduced in OTP release 21.</item> </taglist> </section> @@ -202,8 +207,16 @@ f() -> directive. If that condition is false, the lines following <c>else</c> are evaluated instead.</item> <tag><c>-endif.</c></tag> - <item>Specifies the end of an <c>ifdef</c> or <c>ifndef</c> - directive.</item> + <item>Specifies the end of an <c>ifdef</c>, an <c>ifndef</c> + directive, or the end of an <c>if</c> or <c>elif</c> directive.</item> + <tag><c>-if(Condition).</c></tag> + <item>Evaluates the following lines only if <c>Condition</c> + evaluates to true.</item> + <tag><c>-elif(Condition).</c></tag> + <item>Only allowed after an <c>if</c> or another <c>elif</c> directive. + If the preceding <c>if</c> or <c>elif</c> directives do not + evaluate to true, and the <c>Condition</c> evaluates to true, + the lines following the <c>elif</c> are evaluated instead.</item> </taglist> <note> <p>The macro directives cannot be used inside functions.</p> @@ -231,6 +244,24 @@ or {ok,m}</pre> <p><c>?LOG(Arg)</c> is then expanded to a call to <c>io:format/2</c> and provide the user with some simple trace output.</p> + + <p><em>Example:</em></p> + <code type="none"> +-module(m) +... +-ifdef(OTP_RELEASE). + %% OTP 21 or higher + -if(?OTP_RELEASE >= 22). + %% Code that will work in OTP 22 or higher + -elif(?OTP_RELEASE >= 21). + %% Code that will work in OTP 21 or higher + -endif. +-else. + %% OTP 20 or lower. +-endif. +...</code> + <p>The code uses the <c>OTP_RELEASE</c> macro to conditionally + select code depending on release.</p> </section> <section> |