1

I got thousands of files that have that include files with forward slashes

#include <this/thread.hpp>

Why? the original program was written in VS 2008.

This causes a fatal error C1083

If I change the path to #include "..\this\thread.hpp" it finds the file

jean
  • 13
  • 1
  • 4
  • forward slash should be used for portability http://stackoverflow.com/questions/24186647/c1083-cannot-open-include-file-math-h-no-such-file-or-directory http://stackoverflow.com/questions/13367999/visual-studio-2010-include-directory-paths – phuclv Mar 18 '15 at 11:04
  • 3
    There are three differences between #include and #include "..\this\thread.hpp". Only one of them is the kind of slash used. – sigy Mar 18 '15 at 11:14

3 Answers3

2

Windows accepts both forward- and backslash as path separator. At least since Windows XP.

I cannot read minds, but I could guess that forward slash was used in the name of (potential) portability and/or standards compliance because backslash in an include directive has undefined behaviour in c++03.

c++03 §2.8/2:

If either of the characters ’ or \, or either of the character sequences /* or // appears in a q-char-sequence or a h-char-sequence, or the character " appears in a h-char-sequence, the behavior is undefined.

The wording was changed in c++11 according to the draft. The behaviour is no longer undefined, but still implementation defined.

c++11 draft §2.9/2

The appearance of either of the characters ’ or \ or of either of the character sequences /* or // in a q-char-sequence or an h-char-sequence is conditionally supported with implementation-defined semantics, as is the appearance of the character " in an h-char-sequence.

About your bug:

If I change the path to #include "..\this\thread.hpp" it finds the file

Pay close attention to your two different include directives. There's more difference than the path separator. Firstly, the forward slash version doesn't refer to parent path (../), secondly the path is enclosed in < > which is wrong in this case since it appears that the path is intended to be relative to the current file. See https://stackoverflow.com/a/21594/2079303 for more details.

Community
  • 1
  • 1
eerorika
  • 232,697
  • 12
  • 197
  • 326
0

Error C1083 is "cannot open include file", which typically means that the compiler couldn't find the file.

#include <this/thread.hpp>

Is there a directory called 'this' anywhere in your include directory paths? That is far more likely to be the problem than the forward slash.

arayq2
  • 2,502
  • 17
  • 21
0

While not C++ -specific, it is where using \ is an escape character, at least when it is within the <...> tags, such that if you really wanted to specify it as a path separator, you would need to type \\. To avoid doing double-backslashes every time you want to have only one type of backslash, and because it acts the same way, you can apply the same ability to specify a path separation between folders if you simply use /. This simplicity cuts down on confusion to someone that doesn't understand escaping, so that they do not take an escaped path literally and put it into an Explorer address bar and get confused when it does not take them to the right place.

Note that if it requires <...> tags, you are specifying a system file, while the "..." statement was to include a locally-generated one. These syntaxes are different in their escaping requirements.

vapcguy
  • 7,097
  • 1
  • 56
  • 52