Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hi-tech C compiler Preprocessor Directives

Status
Not open for further replies.

samnang39

Full Member level 2
Joined
Oct 26, 2006
Messages
130
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Location
Cambodia
Activity points
2,246
Please anyone explain me what does it mean?

#ifndef ALWAYS_H
#define ALWAYS_H
 

This checks if ALWAYS_H is defined , if it not then it is defined and the code that followed included, else the code is skipped
there is a #endif missing at the end

#ifndef is if not defined
#ifdef is if defined

read https://www.edaboard.com/threads/236812/#post1011744
 
Usually the name used in the define is similar to the header file, for example for lcd.c you use _LCD_H.
The name used can be anything (NEVER_H or SOMETIMES_H), it doesn't make a difference in the operation of the code, it is just easier to understand it if it is similar to the header name.
 
Thanks for your reply. why we need to define the name ALWAYS_H first? if we not define what happen?
 

Hello!

If you don't define this:
Let's suppose that something in MyDefs.h is used at more than one place.
The compiler finds the item in MyDefs.h. Then in another part of the program,
it finds again the same item, and thinks it is declared twice and complain.

By using #ifndef _MY_DEFS_H_ at the beginning of MyDefs.h, the compiler will
read MyDefs.h a first time (since _MY_DEFS_H_ is not yet defined). But the next
time it tries to read it, it will just skip it since this time it has already been read
and _MY_DEFS_H_ is defined.

Dora.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top