[PATCH] Avoid side effects in putc(), which may be implemented as a macro

Alessandro Rubini rubini-list at gnudd.com
Wed Sep 15 21:45:05 UTC 2010


> The Linux man-page says:

Yes, that's what I checked.
 
>        putc() is equivalent to fputc() except that it may be implemented 
> as a macro which evaluates stream more than once.

exactly.
 
>        putchar(c); is equivalent to putc(c,stdout).

This I didn't notice, my fault.

So I'm partly wrong: putchar must have no ++ inside, like putc. But
definitely not fwrite.

Quoting the Dan Fandrich, one earlier message:

> OpenWatcom for one, defines putchar() as a macro in some configurations,
> so there, at at least, it's not wrong. I changed the fwrite() loop only
> for consistency with the putc() loop immediately below.

So putchar is not bugged, my fault. If you feel fwrite should match
for consistency, that's fine as well. But from your message it looked
it was needed (probably a comment about fwrite would have helped, at
least in the commit message if not in the code itself).

> The current form is equivalent and works just as well as the old,
> with (presumably) no binary size impact.

Yes, that was not my point. There always many equivalent ways to
express some algorightm. But you can't remove the inline ++ without
a reason, because the same construct is used a zillion other times.
I got your patch like "we must remove ++ from fwrite as well", which
is not the case.

> "Wrong" is perhaps too harsh a description.

I'm not a native speaker, so my words look harder than they are meant
to be, so please accept my apologies.

Thank you all for your patience

/alessandro


More information about the busybox mailing list