From 1470e950a722d8369ef5ec7410cb47c0e083b52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 4 May 2016 13:20:05 +0200 Subject: Add documentation --- system/doc/reference_manual/macros.xml | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'system/doc') diff --git a/system/doc/reference_manual/macros.xml b/system/doc/reference_manual/macros.xml index 42ea639b54..350bb1d123 100644 --- a/system/doc/reference_manual/macros.xml +++ b/system/doc/reference_manual/macros.xml @@ -233,6 +233,53 @@ or and provide the user with some simple trace output.

+
+ -error() and -warning() directives + +

The directive -error(Term) causes a compilation error.

+ +

Example:

+ +-module(t). +-export([version/0]). + +-ifdef(VERSION). +version() -> ?VERSION. +-else. +-error("Macro VERSION must be defined."). +version() -> "". +-endif. + +

The error message will look like this:

+ +
+% erlc t.erl
+t.erl:7: -error("Macro VERSION must be defined.").
+ +

The directive -warning(Term) causes a compilation warning.

+ +

Example:

+ +-module(t). +-export([version/0]). + +-ifndef(VERSION). +-warning("Macro VERSION not defined -- using default version."). +-define(VERSION, "0"). +-endif. +version() -> ?VERSION. + +

The warning message will look like this:

+ +
+% erlc t.erl
+t.erl:5: Warning: -warning("Macro VERSION not defined -- using default version.").
+ +

The -error() and -warning() directives were added + in OTP 19.

+ +
+
Stringifying Macro Arguments

The construction ??Arg, where Arg is a macro @@ -253,5 +300,6 @@ io:format("Call ~s: ~w~n",["you : function ( 2 , 1 )",you:function(2,1)]).That is, a trace output, with both the function called and the resulting value.

+ -- cgit v1.2.3