FAQ: slashes in your filenames???

J

Julie

Why does the faq make this statement regarding slashes in paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.16

This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as '\\'.

Comments?
 
C

Christopher Benson-Manica

Julie said:
This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as '\\'.

FWIW, I've been bitten by / vs. \ issues in the past. Whether or not
that behavior is conforming, I'd say it's safer just to use the
delimiter that the implementation prefers...
 
K

Kevin Goodsell

Julie said:
Why does the faq make this statement regarding slashes in paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.16

This seems like completely the wrong answer for this question. Rather than
saying that you should use forward slash as a delimiter, it should say
something to the effect of "refer to your operating system documentation on how
to specify paths/subdirectories, remembering that in a string literal in C++
the back-slash (\) character modifies the following character, and therefore
operating systems that use a backslash as a directory delimiter should be
encoded as '\\'.

It doesn't seem likely that using '/' instead of '\\' will /hurt/ you in
any way -- and it should make the code a bit more portable. For full
portability, I don't think you can assume anything about the directory
separator (or even assume that there are directories, but no one is
likely to complain if you decide to only support systems that support
directories, I think).

-Kevin
 
D

Derek

Julie said:
Why does the faq make this statement regarding slashes in
paths:

"This is because the library routines
on these operating systems handle "/"
and "\" interchangeably. "

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.16

This seems like completely the wrong answer for this
question. Rather than saying that you should use forward
slash as a delimiter, it should say something to the
effect of "refer to your operating system documentation
on how to specify paths/subdirectories, remembering that
in a string literal in C++ the back-slash (\) character
modifies the following character, and therefore operating
systems that use a backslash as a directory delimiter
should be encoded as '\\'.

Comments?

Using the forward slash is very portable. As the answer
correctly states, even operating systems that natively use
"\" (Windows, DOS, OS/2, etc.) provide library routines that
understand "/". So the "/" is very portable -- certainly
better than "\".

So I wouldn't call it "completely the wrong answer," but I
would add a disclaimer that nothing is guaranteed by the
standard about directory delimiters. In fact, nothing is
guaranteed about a directories (or even a filesystem)
existing at all.
 
C

Christopher Benson-Manica

Derek said:
Using the forward slash is very portable. As the answer
correctly states, even operating systems that natively use
"\" (Windows, DOS, OS/2, etc.) provide library routines that
understand "/". So the "/" is very portable -- certainly
better than "\".

I'm sure you're correct, but as I said, for whatever reason forward
slashes proved to be problematic on my Windows implemenation, so I
use back slashes. Most people's mileage will vary...
 
J

Julie

Derek said:
Using the forward slash is very portable. As the answer
correctly states, even operating systems that natively use
"\" (Windows, DOS, OS/2, etc.) provide library routines that
understand "/". So the "/" is very portable -- certainly
better than "\".

Doesn't matter about the relative portability of delimiters -- as far as I
know, the standard doesn't say anything about directory delimiters in file
names.

Therefore, the statement in the FAQ that you should use one form over another
is inherently wrong as it pertains the language.
So I wouldn't call it "completely the wrong answer," but I
would add a disclaimer that nothing is guaranteed by the
standard about directory delimiters. In fact, nothing is
guaranteed about a directories (or even a filesystem)
existing at all.

If it isn't 100% correct, then it is completely wrong, especially when there is
a 100% correct answer.
 
J

John Carson

Julie said:
Doesn't matter about the relative portability of delimiters -- as far
as I know, the standard doesn't say anything about directory
delimiters in file names.

Therefore, the statement in the FAQ that you should use one form over
another is inherently wrong as it pertains the language.

A quick skim over the FAQ should convince you that it departs in many
respects from a pure guide to what is in the standard. There are references
to platforms, compilers, garbage collection and even stuff like LaTeX and
HTML. Perhaps there should be a clearer delimitation between what pertains
to the standard and what does not, but I don't think we should expect the
same legal precision from it that we expect from the standard.
 
D

Derek

Julie said:
Doesn't matter about the relative portability of
delimiters -- as far as I know, the standard doesn't say
anything about directory delimiters in file names.

Relax, it's just a FAQ, not the standard itself. Relative
portability DOES matter to those of us programming in
the real world. And because the standard won't touch
OS-specific issues, I think the FAQ is a perfect place for
real-world answers to real-world questions.
Therefore, the statement in the FAQ that you should use
one form over another is inherently wrong as it pertains
the language.


If it isn't 100% correct, then it is completely wrong,
especially when there is a 100% correct answer.

Yes, the 100% correct answer is that you shouldn't use
files or paths in a portable program because a filesystem
might not exist if the code is ever compiled to run on a
microwave's embedded processor. Not very useful.
 
D

Derek

Julie said:
Doesn't matter about the relative portability of
delimiters -- as far as I know, the standard doesn't say
anything about directory delimiters in file names.

Relax, it's just a FAQ, not the standard itself. Relative
portability DOES matter to those of us programming in
the real world. And because the standard won't touch
OS-specific issues, I think the FAQ is a perfect place for
real-world answers to real-world questions.
Therefore, the statement in the FAQ that you should use
one form over another is inherently wrong as it pertains
the language.


If it isn't 100% correct, then it is completely wrong,
especially when there is a 100% correct answer.

Yes, the 100% correct answer is that you shouldn't use
files or paths in a portable program because a filesystem
might not exist if the code is ever compiled to run on a
microwave's embedded processor. Not very useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top