You are here:

C++/#ifndef preprocessor

Advertisement


Question

Hello, Mr. Bhattacharya

I have the following question

I've been trying to use the #ifndef, #define and #endif preprocessors to avoid multiple file inclusion, but so far I've been unsuccessful

How can I do this?
Can you give me a small example??

Thanks

P.S. I've been searching in books and the net for this but it doesnt provide much info on preprocessors (or if it does,  the info provided is not very detailed). I wonder if this is an old coding practice or uncommon syntax.

Answer
Hi John

Try this for file inclusion

#if !defined( __STDIO_H )
#include <STDIO.H>
#endif  // __STDIO_H

This means if STDIO.H is not defined then define it.

Please lemme know if there is any doubt regarding the same.


regards
Joydeep Bhattacharya
http://www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.