English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Preprocessor in Erlang

Before compiling the Erlang module, the Erlang preprocessor will automatically process the module. The preprocessor will expand any macros that may exist in the source file and insert any necessary include files.

Normally, you do not need to view the output of the preprocessor, but in special cases (such as debugging a macro error), you may want to save the output of the preprocessor. View the preprocessed result of the module some_module. The erl command gives the shell command of the operating system.

erlc -P some_module.erl

For example, assume we have the following code file-

Online Examples

-module(helloworld). 
-export([start/0]). 
-include("user.hrl"). 
start() -> 
   io:fwrite("~w",[?macro1(1,2}).

If we execute the following command from the command line-

erlc –P helloworld.erl

A file named helloworld.P will be generated. If you open this file, you will find the following content, which is the content to be compiled by the preprocessor.

-file("helloworld.erl", 1). -module(helloworld).
-export([start/0]).
-file("user.hrl", 1).
-file("helloworld.erl", 3).
start() ->
   io:fwrite("~w", [{1 + 2}).