All of lore.kernel.org
 help / color / mirror / Atom feed
* Error in scanf(3) man page: "%n"
@ 2011-01-12 16:40 Keith Thompson
  0 siblings, 0 replies; only message in thread
From: Keith Thompson @ 2011-01-12 16:40 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
  Cc: juergen perlinger, linux-man-u79uwXL29TY76Z2rM5mHXA,
	Keith Thompson

juergen perlinger, posting in the Usenet group
comp.std.c, points out an apparent error in the scanf(3)
man page.  The same error exists in the online version at

http://www.kernel.org/doc/man-pages/online/pages/man3/scanf.3.html

The discussion can be seen via

https://groups.google.com/d/topic/comp.std.c/j5g9-orzPc8/discussion

Here's the relevant portion of the man page:

    n   Nothing is expected; instead, the number of characters
        consumed thus far from the input is stored through the
        next pointer, which must be a pointer to int.  This is
        not a conversion, although it can be suppressed with the
        * assignment-suppression character.  The C standard says:
        "Execution of a %n directive does not increment the assignment
        count returned at the completion of execution" but the
        Corrigendum seems to contradict this.  Probably it is wise
        not to make any assumptions on the effect of %n conversions
        on the return value.

Here's the text from the C99 standard, quoted from
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
which includes the C99 standard with all three Technical
Corrigenda.  Changes are marked with change bars; there
are none in this section.

    n   No input is consumed. The corresponding argument shall be
        a pointer to signed integer into which is to be written
        the number of characters read from the input stream so
        far by this call to the fscanf function. Execution of a %n
        directive does not increment the assignment count returned
        at the completion of execution of the fscanf function. No
        argument is converted, but one is consumed. If the conversion
        specification includes an assignment-suppressing character
        or a field width, the behavior is undefined.

The man page's statement that "it can be suppressed with the *
assignment-suppression character" may be incorrect, or it may just
be glibc-specific (an implementation may define the behavior of
something whose behavior is left undefined by the standard); if
the latter, it would be useful to mention this.

I see nothing in any Corrigendum that supports the last two sentences
of the quoted paragraph in the man page.  (There's also nothing
relevant in the 1995 amendment to the C90 standard.)  As far as I
can tell, it's simply wrong.

-- 
Keith Thompson (The_Other_Keith) kst-PZnT/k/XQVA@public.gmane.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-01-12 16:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-12 16:40 Error in scanf(3) man page: "%n" Keith Thompson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.