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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux