Title: | DECC |
Notice: | General DEC C discussions |
Moderator: | TLE::D_SMITH N TE |
Created: | Fri Nov 13 1992 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 2212 |
Total number of notes: | 11045 |
DEC C, OpenVMS ALpha, Port from Unix. Rather than paraphrase my customer's question, I'm posting it as is. Is this possible to do? I can't figure out how if it is. Thanks, Jerry ======================================================= I am trying to port some code from Unix to Open VMS (on an Alpha), and I am having trouble initializing a static FILE * to stdout. Below is an example program and the compiler error message. Is it possible to use stdin and stdout to initialize a global variable? $ type hello.c #include <stdio.h> struct my_struct { FILE *test; }; struct my_struct tests = { stdout }; main() { fprintf(tests.test,"Hello world\n"); } $cc hello.c stdout ..^ %CC-E-NEEDCONSTEXPR, In the initializer for tests.test, "decc$ga_stdout" is not constant, but occurs in a context that requires a constant expression. at line number 8 in file RUSER5:[STAFF.EPPERLY.TMP]HELLO.C;2
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
2186.1 | DECCXL::WIBECAN | That's the way it is, in Engineering! | Tue May 13 1997 17:52 | 19 | |
In short, no. On VMS, stdout is defined as #define stdout (decc$ga_stdout) extern FILE * stdout; stdout is defined as an external pointer-to-FILE, and the value contained in it cannot be determined at compile time. Compare the definition on Unix: extern FILE _iob[]; #define stdout (&_iob[1]) Here, stdout is defined as the address of an external FILE, rather than an external pointer-to-FILE. The compiler can initialize to an external address, just not to the value contained in that address. There are ways around it. Probably the easiest is to initialize the pointer at run time. Brian | |||||
2186.2 | SPECXN::DERAMO | Dan D'Eramo | Tue May 13 1997 21:56 | 29 | |
Where the standard describes the contents of <stdio.h> (section 4.9 of X3.159-1989) it states > stderr > stdin > stdout > > which are expressions of type "pointer to FILE" that > point to the FILE objects associated, respectively, > with the standard error, input, and output streams. It is unportable to assume any more than this. For example, code that assumes these are compile time constant expressions static FILE *fp = stdout; and code that assumes these are lvalues void f(FILE **); void g(void) { f(&stderr); } and code that assumes that these are modifiable lvalues stdin = fopen(filename, "r"); /* that's what freopen is for! */ all lack portability because a particular implementation need not be implemented so that these work. Dan | |||||
2186.3 | Thanks | CSC32::J_HENSON | Don't get even, get ahead! | Wed May 14 1997 10:38 | 3 |
Thanks. I'll pass this on to my customer. Jerry |