FAQ: slashes in your filenames???

Discussion in 'C++' started by Julie, Apr 12, 2004.

  1. Julie

    Julie Guest

    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?
     
    Julie, Apr 12, 2004
    #1
    1. Advertising

  2. Julie <> spoke thus:

    > 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...

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Apr 12, 2004
    #2
    1. Advertising

  3. Julie wrote:

    > 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
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Apr 12, 2004
    #3
  4. Julie

    Derek Guest

    Julie wrote:

    > 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.
     
    Derek, Apr 12, 2004
    #4
  5. Derek <> spoke thus:

    > 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...

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Apr 12, 2004
    #5
  6. Julie

    Julie Guest

    Derek wrote:
    >
    > Julie wrote:
    >
    > > 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 "\".


    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.
     
    Julie, Apr 12, 2004
    #6
  7. Julie

    John Carson Guest

    "Julie" <> wrote in message
    news:
    >
    > 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.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
     
    John Carson, Apr 13, 2004
    #7
  8. Julie

    Derek Guest

    Julie wrote:
    > > 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.


    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.
    >
    > > 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 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.


    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.
     
    Derek, Apr 13, 2004
    #8
  9. Julie

    Derek Guest

    Julie wrote:

    > > 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.


    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.
    >
    > > 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.


    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.
     
    Derek, Apr 13, 2004
    #9
  10. Julie

    Derek Guest

    Sorry -- pressed the wrong button and responded to the wrong
    thread.
     
    Derek, Apr 13, 2004
    #10
  11. Julie

    Derek Guest

    Again. *sigh* :)
     
    Derek, Apr 13, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nils N

    Using slashes as querystring

    Nils N, Feb 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,914
    Nils N
    Feb 8, 2004
  2. Henrik de Jong
    Replies:
    0
    Views:
    377
    Henrik de Jong
    Jun 18, 2004
  3. qazmlp
    Replies:
    5
    Views:
    694
    Michael Dunn
    Apr 7, 2004
  4. B.J.
    Replies:
    4
    Views:
    746
    Toby Inkster
    Apr 23, 2005
  5. Dan Wilkin
    Replies:
    1
    Views:
    265
    robic0
    Jul 17, 2006
Loading...

Share This Page