This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Porting from Win C++ to linux slash vs backslash


barryg wrote:

> Our extensive C++ library that in the past was compiled using windows has the
> following type of #include statments ...
> 
> #include <dir1\dir2\dir3\file.h>

That's a very unfortunate choice on somebody's part.  ISO C99 6.4.7.3
says that \ in the #include is undefined behavior.  Furthermore,
forward-slash is a perfectly valid path separator in Windows, whereas
backslash is not a valid path separator on POSIX systems.  Conclusion:
using forward slashes will work everywhere, using backslashes is
undefined behavior.

> In our example gcc will not find the file.h unless we switch the \ to / in
> the #include.   We'd have to change countless files to do this.

That's a stilly excuse.  You can update "countless files" in seconds
with a single command.

find . -type f -print0 | xargs -0 \
     perl -pei 'm,^#\s*include, && s,\\,/,g'

(Use -i.ext if you want to keep backup copies, otherwise it will be done
in place.  Use -name \*.c or whatever if you want to only match certain
extensions.)

> We also looked through the gcc options for an option that says to flatten
> all directories.

I seriously doubt you will find anything, given the above.

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]