This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: FILE *foo = stderr; ==>`initializer element is not constant'
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: baldwinr at monolithss dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 29 Jan 2005 21:36:31 +1300
- Subject: Re: FILE *foo = stderr; ==>`initializer element is not constant'
- Reply-to: Danny Smith <dannysmith at users dot sourceforge dot net>
Richie Baldwin wrote:
> When trying to compile a c file using stderr, I have the declaration:
> FILE *foo = stderr;
> and it keeps giving me "Initializer element is not constant".
This will happen on windows platfrom because stderr is imported from a dll
library,
Effectively this means:
extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */
#define _iob (*_imp___iob) /* An array of FILE */
#define stderr (&_iob[STDERR_FILENO])
so stderr is indeed not known at compile time.
A workaround is to use an init function:
#include <stdio.h>
FILE * foo;
void intit_foo()
{
foo = stderr;
}
int main()
{
init_foo();
...
}
Danny