Hi Ray,
On Tue, Mar 6, 2018 at 10:40 PM, Ray Hamel <
rayg...@gmail.com> wrote:
> The C, C++ and POSIX standards require EOF to be a negative constant
> expression
> of type int. In all implementations I'm aware of, EOF == -1. The only
> exception
> I can find is that EOF was ^Z ( '\x1A' ) in DOS, which is positive and
> therefore
> already nonconforming. There is no doubt a great deal of existing code
> relying
> on the assumption that EOF == -1, so I think it makes sense to standardize
> this
> convention.
I am not sure there is a lot of code relying on that. Do you have an
example? Code using either the C or C++ standard libraries should be
using EOF (or other ways of detecting the end of file), and therefore
they are not relying on EOF == -1. Code not using the standard library
for I/O is not using EOF at all, so they don't rely on it either.
Therefore, one would think most code out there is not assuming
anything about EOF (and if they do, it is a mistake anyway).
What are the benefits of making EOF == -1 that you have in mind? Even
if you make the standard say that, your code shouldn't/wouldn't rely
on it anyway (since magic constants are not a good idea). On the other
hand, there are some costs to such change: forcing a value for EOF
could actually break invalid code out there (hypothetical code using a
hardcoded different value); and it would make implementing new systems
harder to accommodate to C++ in the future (assuming they use a
different value for EOF).
>
> A more conservative alternative is to require that static_cast<signed
> char>(EOF)
> be negative.
I am not sure I understand why you would want to do such a cast to
begin with -- maybe a use case would clarify your point! :-)
Cheers,
Miguel
>
> Best,
> Ray
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
std-proposal...@isocpp.org.
> To post to this group, send email to
std-pr...@isocpp.org.
> To view this discussion on the web visit
>
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/16a9359c-2d18-4085-9573-305aba68e75d%40isocpp.org.