c - Should "freopen'ed" stdout be closed? -


in c or c++ program can use freopen redirect output (i.e. stdout file descriptor) file (or discard reopening file descriptor /dev/null or sink).

the question is: if so, should take care of closing file descriptor explicitly before program ends execution? why? on platforms? happens in general , in specific case if don't close file descriptor?

  1. should take care of closing file descriptor explicitly before program ends execution?

    from freopen(3) man page:

    the freopen() function opens file name string pointed filename , associates stream pointed stream it. original stream (if exists) closed.

    so no, don't have close original file *. should close 1 freopen call, though. btw - these file * variables, not file descriptors.

  2. why?

    because documentation says don't have to.

  3. on platforms?

    any correctly implement freopen(3) defined c standard.

  4. what happens in general , in specific case if don't close file descriptor?

    the operating system cleans resources used program when program exits.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -