- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This is going to work fantastically well if someone creates a file on unix that contains a backslash in it's name.
Admin
Just use / for all your path-separators, Windows can handle those just fine.
Admin
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.
Edit Admin
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 :-).
Admin
Ah, the good old XKCD 1638...