How to include a file in C and/or C++
c, c++, c-preprocessor, include
Solution
I think you are out of luck with that file name from the `draft C99 standard` section `6.4.7 Header names` the grammar is as follows:
header-name:
< h-char-sequence >
" q-char-sequence "
h-char-sequence:
h-char
h-char-sequence h-char
h-char:
any member of the source character set except
the new-line character and >
q-char-sequence:
q-char
q-char-sequence q-char
q-char:
any member of the source character set except
the new-line character and "
You have both a `"` and `>` in the file name which excludes you from both the `q-char` and `h-char` specification. I don't think you have much choice but to change the file name.
The grammar is the same in the `draft C++ standard`, section `2.9 Header names`.
Problem
I have a header file that I am trying to include from another source file using `include` pre-processor directory. I have tried to use both quoted form as well as angle-braket form, but neither seem to do the job. The file name is `.>"hello.h` and a directory where it is searched by the compiler. I have tried to include it like this: - `#include <.>"hello.h>` - `#include <.\>"hello.h>` - `#include <.\>\"hello.h>` - `#include ".>"hello.h"` - `#include ".>\"hello.h"` I also tried different C and C++ compilers — clang, gcc, clang++ and g++. Obviously, none of the above worked or otherwise there would have been no question. I thought that maybe the name is not legal according to the standard. Unfortunately, I have neither C nor C++ standard specifications on hand. The only authoritative source of information I could find was this MSDN page about `#include` directive, and GNU C preprocessor documentation, here. GNU's documentation does not say much, MSDN has the following clause, however: The path-spec is a file name optionally preceded by a directory specification. The file name must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled. I am curious as to what C and C++ standards say about this? Where do I find those OS-specific rules for C and C++ header file naming requirements? I am particularly interested in OS X, Linux and FreeBSD. Why escaping `<` and/or `"` characters does not work? How do I include my file?