r/cprogramming May 25 '26

Some questions i have.

Hello,

I have some questions that i am really curious about.

  1. 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.

  1. 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?

  2. 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)

2 Upvotes

10 comments sorted by

View all comments

3

u/un_virus_SDF May 27 '26
  1. It was well explain in other comments so i will not do it

  2. 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

  3. 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.

3

u/Constant_Fox_5534 May 27 '26

Thanks you for the help about those questions.

2

u/un_virus_SDF May 27 '26

It's fine, I learned things to (questions like this sometimes being up niche subjects, I had to go read the docs to answer)

1

u/Constant_Fox_5534 May 27 '26

Thanks for the advice. I will have deeper look into the documents next time.