c - Confusing language in specification of strtol, et al -
c - Confusing language in specification of strtol, et al -
the specification strtol
conceptually divides input string "initial whitespace", "subject sequence", , "final string", , defines "subject sequence" as:
the longest initial subsequence of input string, starting first non-white-space character of expected form. subject sequence shall contain no characters if input string empty or consists exclusively of white-space characters, or if first non-white-space character other sign or permissible letter or digit.
at 1 time thought "longest initial subsequence" business akin way scanf
works, "0x@"
scan "0x"
, failed match, followed "@"
next unread character. however, after discussion, i'm convinced strtol
processes longest initial subsequence of expected form, not longest initial string initial subsequence of possible string of expected form.
what's still confusing me language in specification:
if subject sequence empty or not have expected form, no conversion performed; value of str stored in object pointed endptr, provided endptr not null pointer.
if take seems right definition of "subject sequence", there no such thing non-empty subject sequence not have expected form, , instead (to avoid redundancy , confusion) text should read:
if subject sequence empty, no conversion performed; value of str stored in object pointed endptr, provided endptr not null pointer.
can clarify these issues me? perhaps link past discussions or relevant defect reports useful.
i think c99 language quite clear:
the subject sequence defined longest initial subsequence of input string, starting first non-white-space character, of expected form.
given "0x@"
, "0x@"
not of expected form; "0x"
not of expected form; hence "0"
longest initial subsequence of expected form.
i agree implies cannot have non-empty subject sequence isn't of expected form - unless interpret following:
in other "c"
locale, additional locale-specific subject sequence forms may accepted.
...as allowing locale define other possible forms subject sequence might have, nonetheless not of "the expected form".
the wording in final paragraph seems "belt-and-braces".
c standards-compliance language-lawyer strtol
Comments
Post a Comment