views:

453

answers:

5

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

#include <ThisIsAheaderFile.h>

Is there a way to enforce case sensitivity so that the #include will result in an error?

+10  A: 

No, 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.

RichieHindle
You can write iF.. includes ... boiler plate to do this for each file. <Shudder>
WolfmanDragon
Actually, that's not quite right. NTFS retains the case of filenames as part of POSIX compliance, but maps everything to upper case when doing file operations. http://blogs.msdn.com/michkap/archive/2005/01/16/353873.aspx
Tim Sylvester
C++ runs on more than just Windows boxes.
WolfmanDragon
I rember having a problem where it turned out there were two files (RICHIE.h and richie.h (they differed only in case)) Win manipulated the first one it found in the directory structure.
Martin York
@WolfmanDragon: This question is specifically about Visual Studio.
RichieHindle
@WolfmanDragon: Because it runs on different platforms it has to take into account that some platforms are simply not case sensitive in the file system. Hence the behavior.
Chris Lively
+1  A: 

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.

Jason
+1  A: 

I have seen this be a problem when working with Unix code bases that may use two versions of the same file name, but with different case.

I still remember my feeling of disbelief when a friend of mine glowingly told me of this feature of the cool new system he'd learned, called "Unix". I just could not believe someone thought that having files "Cat" and "cat" be different things was actually a feature, and not just a bug caused by some idiot who decided to save a few CPU cycles by not same-casing names before comparison.

John Saunders
+1  A: 

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.

Tim Sylvester
Sounds like a real good reason not to do that.
John Saunders
A: 

Not a single person has actually answered the question: how do you enforce case sensitivity in the preprocessor?

I have no idea, but this is one of the reasons why I always compile my code regularly on Linux or using MinGW.

It's obvious that the Windows filesystem is case insensitive, but that has little to do with the preprocessor in VC, don't you think? :)

jacmoe