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
Post a Comment