public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david.brown@hesbynett.no>
To: gcc-help@gcc.gnu.org
Subject: Re: [GCC][Windows] header file inclusion on windows
Date: Sat, 28 Jan 2023 15:04:08 +0100	[thread overview]
Message-ID: <tr3a0p$fkl$1@ciao.gmane.io> (raw)
In-Reply-To: <CAKdR=ovAm3Zs6nEsuTjbWRFiMpbX5n2zTS5Gn7UYutt4+4otVA@mail.gmail.com>

On 28/01/2023 04:57, Mena Makary via Gcc-help wrote:
> Hello GCC Help Team,
> 
> Could you please support on the following C code example:
> 
> #include "header.h"   /* Proper file name like on windows file system, No
> error is expected */
> #include "Header.h"  /* Same file but H letter is camelcased by mistake,
> Error is expected */
> #include "header.h "  /* Same file but a space is added before end of file
> inclusion by mistake, Error is expected */
> 
> The problem here is that the above two issues are not detected by GCC
> on windows, while could be detected on Linux.
> Is there any compiler option/flag enables GCC to detect such issues on
> Windows?
> 

I think this is inevitable for Windows.  The compiler will ask for the 
header by trying to open a file called "header.h", "Header.h" or 
"header.h ", and the OS will give them file, because on Windows these 
all refer to the same file due to case-insensitive and space-striping 
names.  So the compiler has no way to report this as an issue - because 
on Windows, it is /not/ an error.  It is the expected behaviour of the 
system.

In theory, I suppose, the compiler could ask for a details of the file 
or a directory listing, and compare the stored name (as file names are 
case-preserving in Windows) to the name requested by the pre-processor. 
But that would be a lot of extra work for no purpose for a compiler, and 
would break code that currently compiles fine on Windows.

I don't know what you are aiming to do here.  But one possibility is to 
use one of the "-M" options for gcc to create a "make" dependency file 
that lists the headers included by the file.  A small Python script 
could parse that, read the true filename for the file on the Windows 
filesystem, and compare them.

Another possibility is to run the compilation using a Cygwin 
environment, rather than more common mingw gcc builds.  Under Cygwin, 
filenames are case sensitive.




  reply	other threads:[~2023-01-28 14:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  3:57 Mena Makary
2023-01-28 14:04 ` David Brown [this message]
2023-01-28 17:38   ` NightStrike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='tr3a0p$fkl$1@ciao.gmane.io' \
    --to=david.brown@hesbynett.no \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).