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

Alessandro Rubini rubini-list at gnudd.com
Wed Sep 15 10:01:00 UTC 2010


Sorry for the delay, I know this is an old thread, but I'm recovering
after being offline and I see nothing more in this same thread.

To recap, this patch was accepted:

> -		putchar(*name++);
> +		putchar(*name);
> +		++name;

> -			fwrite(buf, 1, c, *fp++);
> -		while (*fp);
> +			fwrite(buf, 1, c, *fp);
> +		while (*++fp);

[...]

But putchar and fwrite cannot evaluate the arguments more than once.
So the patch is fine for putc (the part I don't quote here), but
is wrong (i.e., unneeded) for the two hunks above.

If a library implementation has double evaluation for putchar and
fwrite, it's the library that's broken; I think we don't special-case
for broken tools, at least not without making a comment.  Or do we
want to remove all ++ and -- because functions may be broken?

Sorry for the seemingly-harsh words, it's not my intention but I'm
not a native speaker.

thanks
/alessandro


More information about the busybox mailing list