On 6/15/24 9:29 AM, Koichi Murase wrote:

I still feel it would be best if POSIX could be updated to allow the
implementations to extend the interpretation when the conversion by
strtod(3) fails. The current restriction is not an explicit one but
something deduced from the four statements of the POSIX:

1) the floating-point conversion (%f, etc) of the printf utility is
performed by strtod(3),
2) strtod(3) uses LC_NUMERIC to determine the radix character,
3) strtod(3) "fails" by setting endptr = nptr when the string does not
have an expected form,
4) the printf utility needs to print a diagnostic message and fail
when the argument is not converted to a value appropriate to the
conversion specification (%f, etc.).

I doubt that the current restriction on the printf utility not
allowing C floating-point literals is intentional.

I'm pretty sure it is. If you assume that all string-to-float conversions
are performed using strtod/strtof/strtold - the standard provides no other
way to do that - then the explicit mention of strtod prevails, for
consistency's sake if no other. The standard would not refer to strtod
explicitly if it did not want to inherit strtod's restriction to a locale-
specific radix character. In other places where the standard relaxes such
restrictions, it does so explicitly ("if the implementation wishes to allow
additional formats, blah, blah").

Now, you might be able to file an interpretation request and get the group
to (grudgingly) allow `.' and the locale's radix character to be used
interchangeably.

Is there a reason
that we should not interpret C floating-point literals (except the
passive reason that a non-trivial combination of POSIX statements does
not allow it)?

I think it's pretty explicit.

I feel it is better to allow the printf implementations
to extend the conversion rather than trying to invent strange and
inconsistent behaviors among the arithmetic expressions, the
arithmetic expansions, and the parameter expansions just to work
around the problem.

I might be able to do that as a settable shopt option that gets turned
off in posix mode, in a later version.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to