-2

How can I use directory in preprecessor command ifndef

EXAMPLE

#ifndef DIR/HEADERFILE_H 
#include "dir/headerfile.h"
#endif
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dušan Tichý
  • 498
  • 1
  • 7
  • 21

2 Answers2

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 
Community
  • 1
  • 1
SimoV8
  • 1,382
  • 1
  • 18
  • 32
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.

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62