#line 指令的 nul.h 文件名的文件路径不正确

Incorrect file path for nul.h filename of #line directive

问题

msvs14 上,使用 #line 指令,filenamenul.h 结尾,例如:

#line 1 "nul.h"

将不正确的文件路径显示为神秘的 \.\nul 而不是 __FILE__/../nul.h

例子

#pragma message(__FILE__)
#line 1 "../../nul.h"
die();

产生:

1>  c:\users\benio\documents\visual studio 2015\node\utils\lists.h
1>\.\nul(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

问题

  1. 为什么会这样?
  2. 这个神秘\.\nul的来源是什么?

啊啊啊!你被一个非常讨厌的向后兼容性所困扰,它可以追溯到 DOS 1.0 左右。

有几个名称(NUL、CON 和 PRN 是示例)是 special(NUL 是空设备,CON 是控制台,PRN 是打印机)。问题是这些神奇的名字早于目录并忽略文件扩展名——所以每当编译器试图打开“”。\nul.h"`,Windows 发现这个,说 "Ah ha! You are probably running a program which relies on DOS backwards compatability, and you want to open the null device instead" - 所以编译器出错。

\.\nul 是 nul 设备的规范名称。

Tl;dr:您必须更改包含文件的名称。取而代之的是 "null.h"