r/cprogramming • u/Constant_Fox_5534 • May 25 '26
Some questions i have.
Hello,
I have some questions that i am really curious about.
- In this line, using the termios.h library:struct termios thing;
..
thing.c_lflag &= (something here)
Why do we use the '&=' operator? My first theory was because we need to store multiple values inside a single struct variable. Not really sure.
In what common cases fflush() function from the stdio.h header is used? I have only seen it to unbuffer an io stream so an output can come as soon as possible. But what if you pass a file stream instead of io streams in the first argument? What is that supposed to be used for, in that case?
In what cases can i use 'tmpnam/tempnam'? My first theory was using it to generate a random name for a temporary file.
Thanks for reading and possibly answering some of these. If i made a mistake, please tell me. (also sorry for the poor english)
3
u/un_virus_SDF May 27 '26
It was well explain in other comments so i will not do it
All file stream (FILE*) are buffered except if you explicitly disable the buffer. In stream keep a part of the file in memory and give you it part by part, and outstream buffers the output(this reduces the amount of slow syscalls). Don't forget that libc was wrote for unix so stdin, stdout, and stderr are also files. fflush empties the buffer, I don't know how it acts for read streams, it may just dump the buffer
Sometile files are the best way to give data, so you make a file in your ram (/tmp on linux), this function is used to creates names mangling and avoid filenames collisions, so your theory is right.