- Erlang - Web Programming
- Erlang - Drivers
- Erlang - Performance
- Erlang - Concurrency
- Erlang - OTP
- Erlang - Distributed Programming
- Erlang - Ports
- Erlang - Databases
- Erlang - Emails
- Erlang - Processes
- Erlang - Funs
- Erlang - Binaries
- Erlang - BIFS
- Erlang - Guards
- Erlang - Pattern Matching
- Erlang - Preprocessors
- Erlang - Header Files
- Erlang - Macros
- Erlang - Exceptions
- Erlang - Records
- Erlang - Tuples
- Erlang - Maps
- Erlang - Atoms
- Erlang - File I/O
- Erlang - Lists
- Erlang - Strings
- Erlang - Numbers
- Erlang - Recursion
- Erlang - Modules
- Erlang - Functions
- Erlang - Decision Making
- Erlang - Loops
- Erlang - Operators
- Erlang - Variables
- Erlang - Data Types
- Erlang - Shell
- Erlang - Basic Syntax
- Erlang - Environment
- Erlang - Overview
- Erlang - Home
Erlang Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Erlang - Header Files
Header files are pke include files in any other programming language. It is useful for spptting modules into different files and then accessing these header files into separate programs. To see header files in action, let’s look at one of our earper examples of records.
Let’s first create a file called user.hrl and add the following code −
-record(person, {name = "", id}).
Now in our main program file, let’s add the following code −
Example
-module(helloworld). -export([start/0]). -include("user.hrl"). start() -> P = #person{name = "John",id = 1}, io:fwrite("~p~n",[P#person.id]), io:fwrite("~p~n",[P#person.name]).
As you can see from the above program, we are actually just including the user.hrl file which automatically inserts the –record code in it.
If you execute the above program, you will get the following output.
Output
1 “John”
You can also do the same thing with macros, you can define the macro inside the header file and reference it in the main file. Let’ see an example of this −
Let’s first create a file called user.hrl and add the following code −
-define(macro1(X,Y),{X+Y}).
Now in our main program file, let’s add the following code −
Example
-module(helloworld). -export([start/0]). -include("user.hrl"). start() -> io:fwrite("~w",[?macro1(1,2)]).
If you execute the above program, you will get the following output −
Output
{3}Advertisements