6

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?

NoobsArePeople2
  • 1,986
  • 14
  • 21
  • Possible duplicate of [When including header files, is the path case sensitive?](http://stackoverflow.com/questions/1951951/when-including-header-files-is-the-path-case-sensitive) – IInspectable May 14 '16 at 15:28

4 Answers4

4

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.

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
  • The filesystem is not what controls case-sensitivity of the search. It's the compiler (see 16.2.2 [cpp.include]: *"How the places are specified or the header identified is implementation-defined."*) – IInspectable May 14 '16 at 15:07
4

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.

bames53
  • 86,085
  • 15
  • 179
  • 244
  • 1
    I'll upvote this one since it's the only one to state that it's implementation defined rather than OS-defined. ISO states that the handling of the strings within include statements is pretty much totally up to the implementation. Normally, that would map to the underlying file system properties but that's not necessarily the case. In fact, there's no requirement that headers be on a file system at all :-) – paxdiablo Feb 26 '12 at 03:18
2

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.

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
  • How does the compiler know the difference between `XInput` and `Xinput`? – NoobsArePeople2 Feb 26 '12 at 02:52
  • Those are class names, not filenames. Classes and other C things are always case sensitive. – StilesCrisis Feb 26 '12 at 02:54
  • 2
    @NoobsArePeople2: The *compiler* doesn't know the difference between these files. The compiler gets the file a that the operating system gives it. C++ source is case-sensitive, regardless of the OS, and this includes the `class` names (but not their files). – johnsyweb Feb 26 '12 at 02:55
  • @StilesCrisis no they're not class names. They are file names. – Seth Carnegie Feb 26 '12 at 02:58
  • 2
    You mean, why is the autocomplete showing two options with different case? There are two files that autocomplete found named XInput, and each is capitalized differently. Don't read too much into autocomplete. It is stupid sometimes. – StilesCrisis Feb 26 '12 at 03:24
  • Sorry, had to downvote this answer for being factually wrong. It's neither the OS nor the filesystem that dictates, whether `#include` directives are case-sensitive. Case-sensitivity is implementation-defined, and it's the compiler that gets to decide. From 16.2.2 [cpp.include]: *"How the places are specified or the header identified is implementation-defined."* – IInspectable May 14 '16 at 15:06
  • OK, spec wizard, have you ever seen an implementation that doesn't follow the OS here? Every compiler I've ever worked with (across Mac, Linux, and Windows) honors the OS casing rules. Yes, by the spec they are allowed to do something different, but I've never experienced a compiler which deviated. – StilesCrisis May 14 '16 at 15:25
  • The question is *"Does case-sensitivity matter when including header files?"* and I gave an answer to that question. Picking the underlying OS' or filesystem's case sensitivity for the search may be a natural choice, but there is no requirement to do so (you could implement case sensitive file search on Windows/NTFS just as well). Besides, the statement *"On Windows, filenames are not case-sensitive"* is wrong in itself (see [Naming Files, Paths, and Namespaces](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx)). Name-calling or not, this answer is all-around wrong. – IInspectable May 14 '16 at 16:18
1

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.

Ajay
  • 18,086
  • 12
  • 59
  • 105