From 46237d41e7455ae5801d78e85a82216b73697f44 Mon Sep 17 00:00:00 2001 From: Tomas Abrahamsson Date: Wed, 9 May 2018 00:20:53 +0200 Subject: macros.xml: Document ?OTP_RELEASE, -if and -elif --- system/doc/reference_manual/macros.xml | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'system') 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) -> The name of the current function. ?FUNCTION_ARITY The arity (number of arguments) for the current function. + ?OTP_RELEASE + The OTP release that the currently executing ERTS + application is part of, as an integer. For details, see + erlang:system_info(otp_release). + This macro was introduced in OTP release 21. @@ -202,8 +207,16 @@ f() -> directive. If that condition is false, the lines following else are evaluated instead. -endif. - Specifies the end of an ifdef or ifndef - directive. + Specifies the end of an ifdef, an ifndef + directive, or the end of an if or elif directive. + -if(Condition). + Evaluates the following lines only if Condition + evaluates to true. + -elif(Condition). + Only allowed after an if or another elif directive. + If the preceding if or elif directives do not + evaluate to true, and the Condition evaluates to true, + the lines following the elif are evaluated instead.

The macro directives cannot be used inside functions.

@@ -231,6 +244,24 @@ or {ok,m}

?LOG(Arg) is then expanded to a call to io:format/2 and provide the user with some simple trace output.

+ +

Example:

+ +-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. +... +

The code uses the OTP_RELEASE macro to conditionally + select code depending on release.

-- cgit v1.2.3