Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case Sensitivity in C++ Header Files

I'm a complete noob when it comes to C++ and I've been hacking away on Moai trying to add support for an Xbox 360 gamepad via XInput. When I include the header for XInput there are two options:

  1. XInput XInput

and

  1. Xinput Xinput

Further, in order to use XInput I need to include windows.h. All the examples I've seen use the following syntax:

#include <windows.h>

But the auto complete in Visual C++ Express 2010 inserts

#include <Windows.h>

Windows.h

In the case of XInput/Xinput it seems that case-sensitivity matters but in the case on Windows.h it does not seem to matter.

Does case-sensitivity matter when including header files? Is there some logic to this?

Is the XInput difference simply a matter of there being a header for something called XInput and another something called Xinput?

like image 862
NoobsArePeople2 Avatar asked Feb 26 '12 02:02

NoobsArePeople2


People also ask

Is header file name case-sensitive in C?

Its not C++ standard, its the Linux way, where all path names are case sensitive. The best practice is too chose whatever file name you want ( mostly lowercase) and use the same case in the include directive.

What are case-sensitive files?

Case-sensitive file-systems: This is the file-system generally used on Linux - 2 files can differ only by case, and the exact case must be used when opening a file. Case-insensitive, case-preserving (cicp) file-systems: This is the file-system generally used on Windows; FAT32 is an example of such a file-system.

Which file naming is case-sensitive?

File names: Traditionally, Unix-like operating systems treat file names case-sensitively while Microsoft Windows is case-insensitive but, for most file systems, case-preserving.

Are C keywords case-sensitive?

Because C is case-sensitive and those are the keywords. Making them case-insensitive would have made the compiler slower, but the real reason is that's how it was defined. There was a lot of experimentation with letter case in the 60s.


4 Answers

Case sensitivity in header names and include directives is implementation defined. Generally it works out to whether the platform you're building on is case sensitive or not.

I'd have to test to make sure, but I suspect that if you type any variety of 'xinput.h' it will find the the one that occurs first in the header search paths, even if the file that occurs later in the search paths is a better match in terms of case. This would be quite unintuitive from the perspective of a developer not familiar with these issues, because it would mean that you could use one of those auto-completions, and VS would then include the file not selected.

It's also possible that VS is smarter than that and will search for the best case match.

like image 170
bames53 Avatar answered Sep 29 '22 21:09

bames53


It only matters if the underlying file system is case sensitive. The Windows filesystem is not case-sensitive, but the file systems of operating systems like Linux are. Try to use the exact actual name of the real file to ensure that your code works if/when you port it from one OS to another.

like image 22
Seth Carnegie Avatar answered Sep 29 '22 19:09

Seth Carnegie


On Windows, filenames are not case-sensitive, and this extends to #include. Any case will do.

On some platforms (e.g. Linux), filenames are case-sensitive, so you would need to match the actual filename.

like image 45
StilesCrisis Avatar answered Sep 29 '22 21:09

StilesCrisis


Windows is not case sensetive as others have said. But that's not your problem. Your problem is with include-file settings in Visual Studio. The compiler will look for standard headers (header inclusion using <> syntax), in the order they are setup. Launch Tools->Options, and then lookup Projects and Solutions->VC++ directories and see the sequence of Include Files.

like image 39
Ajay Avatar answered Sep 29 '22 21:09

Ajay