Mail Archives: djgpp/1996/12/14/10:18:42
Thomas Harte wrote:
>
> HELP! All of a sudden, under DJGPP V2, the lines :-
>
> unsigned char *vbuf = (unsigned char *)malloc(64000);
> unsigned char *doublebuffer = (unsigned char *)malloc(64000);
> unsigned char *background = (unsigned char *)malloc(64000);
>
> have started coming up with the error 'initialiser element is not
> constant', and I don't know why.
are these global variables? AFAIK, you cannot initialize global
variables with non constant values. the initializer element not
constant message has nothing to do with the argument to malloc. instead,
it is the initializer for the pointers you define. since the return
value of malloc is not constant (it either null or a pointer to the area
of memory allocated), you cannot define global variables this way.
it should not be a problem declaring these global variables first and
the initializng them in a separate function. in fact, that is probably
preferable because that way you can check for the failure of malloc and
act accordingly. ;-)
sinan.
--
*******************************************************************
A. Sinan Unur WWWWWW
|--O+O
mailto:asu1 AT cornell DOT edu C ^
mailto:sinan AT econ DOT cit DOT cornell DOT edu \ ~/
http://www.bqnet.com/sinan/
*******************************************************************
- Raw text -