Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is setbuf useful (besides the NULL value)?

Tags:

c++

c

When is the setbuf function useful (except the NULL value)?

I try to invent the examples, but I can't still.
I understand how setvbuf can be useful, but I don't understand with setbuf.

like image 907
Andrey Bushman Avatar asked Mar 03 '26 09:03

Andrey Bushman


1 Answers

Basically, setvbuf is a newer API to the same logic as setbuf. setbuf exists for compatibility with programs that were written before setvbuf existed.

So in other words, unless you're dealing with code that already uses setbuf, just ignore that it exists.

Reference:

Function: void setbuf (FILE *stream, char *buf)

  • If buf is a null pointer, the effect of this function is equivalent to calling setvbuf with a mode argument of _IONBF. Otherwise, it is equivalent to calling setvbuf with buf, and a mode of _IOFBF and a size argument of BUFSIZ.
  • The setbuf function is provided for compatibility with old code; use setvbuf in all new programs.
like image 170
Bill Lynch Avatar answered Mar 06 '26 00:03

Bill Lynch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!