• Greg (unregistered)

    This is going to work fantastically well if someone creates a file on unix that contains a backslash in it's name.

  • A.N.O Nymos (unregistered)

    Just use / for all your path-separators, Windows can handle those just fine.

  • Rainer Deyke (unregistered)

    User code with backslashes as path separators is an abomination. Low level C/C++ file operations support, and have always supported, backslashes.

    Slight exception for the presentation layer, because users expect backslashes. But only the presentation layer. Convert to backslashes on output, convert to forward slashes on input.

  • (nodebb)

    In my decades of software development, different file IO systems were always a pain in the butt. Now these days a lot of people only think there are two but in the past there were many different ones and all of them had a quirk here and there.

    Still, while Windows supports both directory separators, it's very important to note that this support means that all alternative directory separators are actually get converted (normalized) before usage internally and since all functions support const literals that means allocating a buffers. So there is a significant cost involved with using alt directory separators and you still should always use the native versions over the common '/'.

    Now is there a good way to get around this? Nah. There is actually way more to it than just the directory separator since file systems are often completely different in terms of structure and features. Linux is real links and ignoring that could end up in an endless recursion why enumerating directories. Windows had drives, which are not only not bound to letters that can change, they actually often will when you work with multiple removable devices. And finally the whole permission system is completely different, down to what classifies as an executable. And I just mentioned here a few pitfalls on the top of the iceberg. So just using an directory separator macro isn't enough in a well thought out software, you really need to abstract away the OS in a way more involved way to the point that it's really hard to pull this off on a zero cost basis; which means it's often better to do it inline. Sucks for readability, sure, but beats using a bloated, slow, resource hungry IO framework.

    Addendum 2026-06-29 08:01: Linus is real links? Ha, I guess it has them but eh, I blame the heat wave here :-).

  • Frodo Brömmelkamp (unregistered)

    If we're compiling for unix, append a "/" to the filename. Otherwise, append a "". Then we append a path out of an array. Then, if we're on Windows, find all the "/" in our filename and replace them with "". Otherwise, find all the "" in our filename and replace them with "/".

    Ah, the good old XKCD 1638...

Leave a comment on “Off the Path”

Log In or post as a guest

Replying to comment #:

« Return to Article