পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, January 31, 2017

Erlang - Header Files

Header files are like include files in any other programming language. It is useful for splitting 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 earlier 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}

No comments:

Post a Comment