c - Assigning stdout to a FILE* -


as code global scope in small c program have:

file *outfile = stdout; 

this because want have stdout default destination output allow users specify different 1 on command line (though know redirect wanted belt , braces).

this fails compile:

xmlheap.c:15:17: error: initializer element not compile-time constant file *outfile = stdout;             ^~~~~~ /usr/include/stdio.h:215:16: note: expanded macro 'stdout' #define stdout  __stdoutp 

is not possible?

static initializers in c have compile-time constants. since stdout not required such, have initialize global variable in dynamic program execution:

#include <stdio.h>  file * outfile;  int main(void) {     outfile = stdout;      /* ... */ } 

(specifically (cf. c11 7.21.1/3), stdout mereley specified macro expands "expressions of type "pointer file"".)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -