Random pet peeve: '\0'

Pages: 1234567
@Disch I did ask a valid questioned relating to the original post earlier:
It gout buried, could you respond to it now?
Last edited on
L B wrote:
what about L"\0" and other variants?

L"\0" is fine as that at least has a purpose. Although there are very few circumstances where you'd need a double-null terminated string.
Er, I meant L'\0' - the double quotes were supposed to be single quotes.
Nah that's just as dumb.
What if you needed to write both regular and unicode null-terminated strings to the same stream?

I will admit, the uses are rare.
What if you needed to write both regular and unicode null-terminated strings to the same stream?

L'\0' isn't a null terminated string. I don't see how this applies.

Can you give an example?
stream << regular_string << '\0' << unicode_string << L'\0' << std::flush;

You can't use std::ends because it can not guess whether the string before it was a regular or unicode string.
Last edited on
ah. Yeah okay there it makes sense.
Another useful purpose (in the Windows world) is about GetOpenFileName:
The files filtering functionality uses a NULL character to split Extension and Description. Obviously the entire "string" ends with a double NULL character.
Yes but that's embedding the null in the middle of a string. IE:

"Text files\0*.txt\0All Files\0*\0"

That's different from referring to a single character.
@Disch thank you, thank you for using "*" for All Files and not "*.*"
@Disch: Yeah, Right.
@LB: No risk with us, I'm used to do that too.
IIRC, in the Windows world "*.*" is more correct than "*".
There are plenty of files that come pre-installed on my machine that have no extension.
That doesn't change the behavior of Windows when pattern-matching files.
It does, because it searches for a matching dot in a filename.
Doesn't it?

Last edited on
Wow, I didn't expect that - it treats *.* as a special case and even displays files with no dots in their name.
Originally, all filenames had a dot (technically), so you aren't actually pattern-matching the dot. You are pattern matching everything before the dot and everything after the dot.

Google "hysterical raisins". :O)
How do I select file with dot and not without one?
(Legit, can send screenshot of entire folder in explorer)
Last edited on
I don't believe you.

That one with the dot at the end must have spaces or some other non-glyph character in the extension.
Pages: 1234567