[patch v1] manual: Document stdio.h functions that may be macros

Florian Weimer fw@deneb.enyo.de
Fri Oct 11 05:53:27 GMT 2024


* DJ Delorie:

>>> diff --git a/manual/stdio.texi b/manual/stdio.texi
>>> index c7a2b4a9a1..fb27dfc6e9 100644
>>> --- a/manual/stdio.texi
>>> +++ b/manual/stdio.texi
>>> @@ -911,9 +911,10 @@ This function is a GNU extension.
>>>  @deftypefun int putc (int @var{c}, FILE *@var{stream})
>>>  @standards{ISO, stdio.h}
>>>  @safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{}}@acunsafe{@acucorrupt{} @aculock{}}}
>>> -This is just like @code{fputc}, except that it may be implemented as
>>> -a macro and may evaluate the @var{stream} argument more than once.
>>> -Therefore, @var{stream} should never be an expression with side-effects.
>>> +This is just like @code{fputc}, except that it may be implemented as a
>>> +macro and may evaluate its arguments more than once.  Therefore,
>>> +@var{c} and @var{stream} should never be expressions with
>>> +side-effects.
>>>  @end deftypefun
>>
>> Why do you mention @var{c} here?  I think the standards only allow it
>> to be evaluated once.
>
> The standard says stream might be evaluated twice, but does not say that
> c will *not* be evaluated twice.

There is a general rule that such macros can only evaluate their
arguments once.  The stream macro parameter is an exception to this
rule.


More information about the Libc-alpha mailing list