How to force Visual Studio preprocessor case sensitivity with #includes?

后端 未结 5 1081
一生所求
一生所求 2021-02-14 03:38

If you have a header file named ThisIsAHeaderFile.h, the following will still locate the file in Visual Studio:

#include 
相关标签:
5条回答
  • 2021-02-14 04:19

    I would like to point out that this is not an unsolvable problem as many tries to point out to the OP. The case insensitivity is beside the point. The point is as Lorenz03Tx explains in a comment, even though the file system is case insentitive the case is retained, so it can be controlled.

    Such a counter measures is really great to have when doing cross platform development, and prevents much after work when the code is compiled for the other platform. Not to forget that making the build process more picky you would induce better habits for the developers, as they gradually will be more consistent how they include and name files.

    TL;DR

    One solution is to use a script that simply scans the source files for include statements and tries to match them along the include paths. Such a script could be added to visual studio post-build events, and thus run at every build, or (inspired by krlmlr) use the preprocessor of a compiler that enforce case sensitivity.

    0 讨论(0)
  • 2021-02-14 04:22

    While it might not be possible to enforce this from within Visual Studio, one could implement a quick check by running only the preprocessor on the C/C++ source. This will run quickly enough to be practicable even as post-commit hook in a version control system, and err if the case in file names has been mismatched. So:

    • Configure your build system in Linux to support preprocessor-only runs (-E with gcc/g++)

    • Implement a preprocessor-only run as post-commit hook, triggering an early notification to the responsible person and/or to someone willing to routinely fix these errors

    Of course, this assumes a VCS as central storage for the code.

    0 讨论(0)
  • 2021-02-14 04:30

    It is (used to be?) possible to create files with the same name but case differences on NTFS. Maybe someone with cygwin can verify this.

    MSDN

    Even then, however, it's impossible to access more than one of these at a time from a normal Windows application.

    0 讨论(0)
  • 2021-02-14 04:31

    Both FAT and NTFS are case insensitive file systems. Foo and fOO are the same file as far as they are concerned. Although the Windows OS will preserve the case you use for a file. If you name a file ThisIsAheaderFile.h it will show up that way in the file system. Although all system function calls to open that file can use any casing they want.

    0 讨论(0)
  • 2021-02-14 04:33

    You can't, because the Windows file system is itself case-insensitive.

    If you could get into a situation where you had both RICHIE.h and richie.h, it might make sense to control case sensitivity, but you can't.

    0 讨论(0)
提交回复
热议问题