-2

How can I use directory in preprecessor command ifndef

EXAMPLE

#ifndef DIR/HEADERFILE_H #include "dir/headerfile.h" #endif 
3
  • 1
    Use a character the preprocessor allows? #ifndef DIR_HEADERFILE_H Commented Nov 7, 2016 at 13:43
  • What are you trying to achieve? The preprocessor understands text - not directory structures? Once a file has been #includedd it doesn't then have the filename/directory #defined. Commented Nov 7, 2016 at 13:50
  • IT IS VERY INTERESTING, WHY I AM GETTING -2? SOME COMMENTS FIRST? Commented Nov 7, 2016 at 14:07

2 Answers 2

1

To answer the specicif question, you cannot use a directory in a preprocessor command like #ifndef.

The include guards in the header file often take the form

#ifndef DIRECTORY_HEADERFILE_INCLUDED #define DIRECTORY_HEADERFILE_INCLUDED //.... contents #endif 

To include the header, then simple use

#include "dir/headerfile.h" 

A long while ago some people suugested a double include guard, or redundant include guard, wherein you checked before the #include line to speed things up, as mentioned in this question. The c2 wiki has some further information esp.

"Good compilers make this idiom unnecessary. "

In either case the tendacny is to use _ instead of /, to form a valid macro.

Sign up to request clarification or add additional context in comments.

Comments

1

As explained in this question, only alphanumeric characters and underscores (a-z, A-Z, 0-9, and _) are allowed for macro and constants names. You can define your own constant replacing / with _:

#ifndef DIR_HEADERFILE_H 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.