473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Is Space Allowed in Filename?

I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code files
accept space between alphabet character and numeric character? Is it the
best practice to use underscore instead of space? If so, please explain
why.
Would you prefer to avoid using two double quote marks in the long
filename if space is there? Without it, it would be underspace.

For example:

#include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work.

What do you recommend which #include ... is best practice?

Bryan Parkoff
Dec 7 '05 #1
13 7148
Bryan Parkoff wrote:
I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code files
accept space between alphabet character and numeric character?
Yes. The only characters prohibited are the newline and the double
quote character.
Is it
the best practice to use underscore instead of space?
No. There is no "best practice".
If so, please
explain why.
Would you prefer to avoid using two double quote marks in the long
filename if space is there?
Huh?
Without it, it would be underspace.
Huh?

For example:

#include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work.
Yes, it is valid. If your file is named "Game<space>Loop.h", where the
<space> designates a single space character, then that's what you need to
give your preprocessor.
What do you recommend which #include ... is best practice?


Do whatever feels better.

V
Dec 7 '05 #2
> #include "GameLoop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game_Loop.h" // Valid Filename so C/C++ Compiler accepts it.
#include "Game Loop.h" // Can it be valid or invalid? It does work


I recomend you to use the first one since most of the people are used
to do so (at least in my country). You may also want to see what's used
to be done in your work place (if it's work that you are doing) or see
what's used to be done in open source projects.

As Victor Bazarov told you there is not such a thing as a best practice
but there are some writing conventions and you may chose to use them or
not. In my case I would use :

#include "gameLoop.h"

Dec 7 '05 #3
Victor Bazarov wrote:
Bryan Parkoff wrote:
Is it
the best practice to use underscore instead of space?wrote


No. There is no "best practice".


May be there isn't any but I'd recommend to use Unix names:
all letters lower-case. This simplifies the usage and makes less
confusions for programmers, especially working on multiplatform
projects (Windows - case insensitive FS, Unix - case sensitive FS).
Consider why SourceForge.net uses Unix names for all hosted projects.
Second, what a rule would you define for files naming in order to make
it easy to use and set it predictable?

This is clear:
#include "MyBrownCar.h"
but what name will you give in case of single-word name:
#include "utils.h"
or
#include "Utils.h"

In this case, naming cohesion may be broken easily:
#include "MyBrownCar.h"
#include "utils.h"

Now, when I go to Unix and I will use
#include "Utils.h", by analogy to MyBrownCar.h then compiler won't find
the file because its name is utils.h.

All other variations like
"My_Brown_Car.h"
or
"My Brown Car.h"
will make the usage a real headache.

If you say "all file names are lower case" there is no problem with all
files on all platforms.

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

Dec 7 '05 #4
Victor Bazarov wrote:
Bryan Parkoff wrote:
I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code files
accept space between alphabet character and numeric character?


Yes. The only characters prohibited are the newline and the double
quote character.


That's wrong. You can specify characters like space in an #include
directive, but how the characters are mapped to actual file names is
implementation-defined. IOW: Whether spaces in header file names are
allowed depends on the implemenation and is usually determined by the
operating system the compiler is running under and the file system the
headers are stored in. Under MSDOS e.g., spaces in file names are not
allowed, and all compilers that I have seen do a 1:1 mapping of the
header-names specified in #include and the actual file names.

Dec 7 '05 #5
> That's wrong. You can specify characters like space in an #include
directive, but how the characters are mapped to actual file names is
implementation-defined. IOW: Whether spaces in header file names are
allowed depends on the implemenation and is usually determined by the
operating system the compiler is running under and the file system the
headers are stored in. Under MSDOS e.g., spaces in file names are not
allowed, and all compilers that I have seen do a 1:1 mapping of the
header-names specified in #include and the actual file names.


1: under DOS you can have spaces, but not two adjacent or at one at the

beginning or the end of a name (not all programs agree, though)
2: IBM's C++ compiler had some weird kind of non-file storage once?
There
is no reason, after all, for headers to be files.
3: Nor do translation units have to be files - they don't even need
preprocessor names!
4: Most compilers that I know use something like /I flags to translate
header
file names into filesystem names. Not a straight 1:1 mapping,
especially if
a single name occurs in more than one directory.
5: The system headers are even weirder, especially on Unix systems
where
some compiler vendors mix OS and C++ headers.

HTH,
Michiel Salters

Dec 7 '05 #6
Bryan Parkoff wrote:
...

What do you recommend which #include ... is best practice?


A ruleset I use (and now my company uses) is:

a) all lower case (reduce issues with case sensitivity on different
platforms).

b) prefix with the namespace or project code (e.g. "at_" for Austria c++
- at_lifetime.h).

c) all header files are ".h" - not .hpp or no suffix like the STL.

d) if the file being included is within the source tree then use '""'
type includes and not "<>" type includes.

So they look like:

#include "##_@@@@@.h"

where ## is a prefix for the subsystem that the header pertains to and
@@@@@ is somthing descriptive.
Dec 7 '05 #7

I forgot one rule.

Gianni Mariani wrote:
Bryan Parkoff wrote:
..

What do you recommend which #include ... is best practice?

A ruleset I use (and now my company uses) is:

a) all lower case (reduce issues with case sensitivity on different
platforms).

b) prefix with the namespace or project code (e.g. "at_" for Austria c++
- at_lifetime.h).

c) all header files are ".h" - not .hpp or no suffix like the STL.

d) if the file being included is within the source tree then use '""'
type includes and not "<>" type includes.


e) No spaces in the file name.

This is because some of the build tools won't deal properly with files
with spaces in them.

So they look like:

#include "##_@@@@@.h"

where ## is a prefix for the subsystem that the header pertains to and
@@@@@ is somthing descriptive.

Dec 7 '05 #8
Gianni Mariani wrote:

b) prefix with the namespace or project code (e.g. "at_" for Austria c++
- at_lifetime.h).


Why not to put namespaces into separate directories -> packages?

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

Dec 7 '05 #9
Mi*************@tomtom.com wrote:
That's wrong. You can specify characters like space in an #include
directive, but how the characters are mapped to actual file names is
implementation-defined. IOW: Whether spaces in header file names are
allowed depends on the implemenation and is usually determined by the
operating system the compiler is running under and the file system the
headers are stored in. Under MSDOS e.g., spaces in file names are not
allowed, and all compilers that I have seen do a 1:1 mapping of the
header-names specified in #include and the actual file names.
1: under DOS you can have spaces, but not two adjacent or at one at the

beginning or the end of a name (not all programs agree, though)


There may be hacks that still make it possible, but Microsoft's FAT
specification says that spaces are not allowed for short file names (which
is what MSDOS uses).
2: IBM's C++ compiler had some weird kind of non-file storage once?
I have heard about that, but don't know any details.
There is no reason, after all, for headers to be files.
Depends on what you mean by "files". From the C++ standard:

************************************************** **********************

16.2 Source file inclusion

1 A #include directive shall identify a header or source file that can be
processed by the implementation.

************************************************** **********************

So it clearly speaks of "files" in conjunction with headers, and not only in
this place. However, it doesn't define how such a file is stored.
3: Nor do translation units have to be files - they don't even need
preprocessor names!
I don't exactly know what you mean by that.
4: Most compilers that I know use something like /I flags to translate
header file names into filesystem names. Not a straight 1:1 mapping,
especially if a single name occurs in more than one directory.
This search sequence is not the mapping that the C++ standard is talking
about.

Something more from section 16.2:

************************************************** **********************

3 A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the
source file identified by the specified sequence between the " delimiters.
The named source file is searched for in an implementation-defined
manner. If this search is not supported, or if the search fails, the
directive is reprocessed as if it read

# include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any)
from the original directive.

************************************************** **********************

So those /I flags are what the C++ standard means by "searched for in an
implementation-defined manner".
5: The system headers are even weirder, especially on Unix systems
where some compiler vendors mix OS and C++ headers.


I haven't seen anything unusual here. They are often using a lot of #defines
and #ifdefs and #include other headers that in turn #include more headers,
but nothing that uses something else than the 1:1 filename mapping.

Dec 7 '05 #10
Rolf Magnus wrote:
Victor Bazarov wrote:
Bryan Parkoff wrote:
I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code
files accept space between alphabet character and numeric character?


Yes. The only characters prohibited are the newline and the double
quote character.


That's wrong. [..]


No, it's not. Read the relevant portion of the Standard.
Dec 8 '05 #11
Victor Bazarov wrote:
Rolf Magnus wrote:
Victor Bazarov wrote:
Bryan Parkoff wrote:
I have seen that C/C++ Compiler supports long filename up to 254
characters plus the extension. Can header files and source code
files accept space between alphabet character and numeric character?

Yes. The only characters prohibited are the newline and the double
quote character.


That's wrong. [..]


No, it's not. Read the relevant portion of the Standard.


I did. That's what made me realize that you are wrong. Maybe you didn't read
my posting?
Dec 8 '05 #12
Rolf Magnus wrote:
Victor Bazarov wrote:
Rolf Magnus wrote:
Victor Bazarov wrote:

Bryan Parkoff wrote:
> I have seen that C/C++ Compiler supports long filename up to
> 254 characters plus the extension. Can header files and source
> code files accept space between alphabet character and numeric
> character?

Yes. The only characters prohibited are the newline and the double
quote character.

That's wrong. [..]


No, it's not. Read the relevant portion of the Standard.


I did. That's what made me realize that you are wrong. Maybe you
didn't read my posting?


And what in it did you give to prove your assertion? Between double
quotes any character is allowed except a newline or a double quote.
Between angle brackets any character is allowed except a newline or
a closing angle bracket (a greater-than sign). What else is there
to contradict my statement? Please, don't foget chapter and verse.

V
Dec 8 '05 #13
Mateusz Loskot wrote:
Victor Bazarov wrote:
Bryan Parkoff wrote:
Is it
the best practice to use underscore instead of space?wrote

No. There is no "best practice".


May be there isn't any but I'd recommend to use Unix names:
all letters lower-case.


Huh? UNIX makes no such restrictions on names. UNIX names
can have pretty much any character except for the nul and slash.
Dec 8 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ted Dawson | last post by:
I have a page that writes a hyperlink to files in a folder, but the hyperlink fails with the space in the filename. How can I strip out that space or replace with &nbsp; ? <%Dim objFSO Set...
5
by: Stu Carter | last post by:
Hi, ENV: Windows 2003 Server SP1 (+all updates), VS 2003, .Net 1.1 SP1 We've got an ASP.Net web application using State Service. All is fine until we tried to use the app through a virtual...
8
by: Larry Lard | last post by:
Today I discovered that a syntax that I thought was forbidden in C# but allowed in VB.NET (and I _don't like_ that it's allowed in VB.NET) is actually allowed in C#. Which confused me. The syntax...
4
by: Paul Hadfield | last post by:
Hi, Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily using the WriteAttributeString method of XmlWriter object, but have run into a problem when trying to output a...
2
by: Sound | last post by:
Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Add a field without giving any name and save the...
1
by: benfly08 | last post by:
Hi, guys. I just wonder whether a space within column name is allowed in SQL Server 2000(i.e. "Item Number" as column name). In a stored procedure i saw: Create table #temp (ExpiryDate...
2
by: Eran.Yasso | last post by:
Hi, My app updates mdb file with no probelm. the problem starts if there's a space on a column name(header consists from two words). I tried all sorts of things. here is my code: private void...
1
by: deerchao | last post by:
I used these codes to provide a default "Save As" filename for browsers: Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); Response.ContentType =...
7
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.