This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FILE *foo = stderr; ==>`initializer element is not constant'


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]