On Wed, 4 May 2016 06:51:38 -0700 (PDT),
stefan.h...@gmail.com
wrote:
>> Eh. There's really very little need to do binary formatted text I/O.
>> Binary literals server a number of programming related purposes, but
>> are not usually something you actually want to input or output.
>
>I'd say there's no less need than for octal output. If there was a good reason to support binary for literals, why doesn't the same reason apply for I/O? I frequently write low-level code which works directly with hardware, and binary would quite frequently be the best format for displaying the value of a register, for example. Or imagine writing a debugger.
Adding octal (and hex) to some of the default input functions was a
mistake. Having them as options would have made sense, and would
probably have provided a path to adding binary text I/O as well. But
we are where we are. And yes, there are small use cases for binary
text I/O.
>But even if you were right, wouldn't consistency alone be a good motivation already?
Consistency is a good thing. Right up to the point where it gets in
the way of a good, useful, and easy to implement feature (like binary
literals), because it's difficult to figure out how to support it in
places we really don't care about anyway.
>> Sure, we can find an occassional use case here and there, but not
>> something I really think needs any serious effort. There are also
>> places where adding binary to text I/O would add some
>> incompatibilities. What, for example, should strtol() or scanf() do
>> with something that looked like a binary literal in the input? If you
>> interpret it as such, you may well be changing existing behavior.
>> Probably best to leave it alone.
>
>Yes, there's a risk of changing the behavior in some corner cases. I haven't spent any time to find out what those cases are and whether they would have to be considered serious. That's open for debate.
And the committee has always been far more reluctant to introduce
changes that can cause even minor breakage. Even more so if it
introduces silent *runtime* breakage. So my guess is that requiring
the change to strtol or scanf would have made binary literals
impossible to get through the committee. But if you can define a set
of changes (possible even excluding the legacy C functions), that
don't break anything (and the normal cin/cout stuff may be there), you
may have a shot. And I certainly wouldn't object, I just would
continue to mostly not care.
>Anyway, strtol() and scanf() are C functions, not C++. I would opt for changing their behavior only once C starts supporting binary literals. That would be for the C standards group to consider.
They're included in the C++ standard by reference.