How this code fragment in print.cpp ever works? #5754
-
|
The current file location: Line 43 in 48db51b GetConsoleMode() says that console is Unicode. But that's not true, or I didn't understand something? Sorry for (possibly) stupid question
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
You can check the comment above this call, it says: // We can check if _Console_handle actually refers to a console or not by checking the
// return value of GetConsoleMode().If |
Beta Was this translation helpful? Give feedback.
-
|
The answer by @jovibor is on the right track. Further elaboration:
The value that indicates Unicode mode is the value returned in "_Console_mode". "_Is_unicode_console" is not an accurate name and that's not the variable that indicates Unicode mode or not. "_Is_unicode_console" is a pass/fail status value that has nothing to do with the console mode (e.g. Unicode). See this example: Then, if status is true (OK), the actual value of interest is _Console_mode. |
Beta Was this translation helpful? Give feedback.
I see, after looking into doing this rename, I think I understand the original rationale.
The
_Console_modecould be renamed to_Unused_modefor a bit more clarity. However,_Is_unicode_consoleis consistent with naming/comments everywhere else. The part that I was confused about, is that "is Unicode console" seems to imply that we're worried about dealing with non-Unicode consoles. But there are no such things. Every console is Unicode like every kitty is cute. We're just trying to distinguish Unicode consoles from non-Unicode non-consoles (redirected to files, I believe).I might rename the mode later but we should keep the bool as-is for consistency with the rest of the codebase.