logoalt Hacker News

rwmj • yesterday at 10:03 AM • 1 reply • view on HN

Annoyingly this doesn't detect certain errors. This is one thing I'd like to change in the next C standard, but (from discussions I had with someone who works in those standards) they don't want to break existing code. Which seems like a very bogus justification to me as that code is broken already.

Also the locale thing could be solved by adding another %-directive to say "this format string should be treated in the C locale", like %C (if it's not already used).

IOW this could be made to work, but human factors prevent it.


Replies

CamperBob2 • yesterday at 4:01 PM

On my machine it detects overflows just fine, returning Inf and -Inf, and also correctly rounds underflows to 0 and -0. But the function itself still returns 1 for overflows/underflows, so it's up to the caller to filter out infinities.

I guess that backs up the complaint about portability, if sscanf() doesn't behave that way on all platforms. But on MSVC its behavior is reasonable enough.