www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/14/10:18:42

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problems with malloc (I think)
Date: Thu, 12 Dec 1996 12:47:10 -0500
Organization: Cornell University http://www.cornell.edu
Lines: 33
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <32B0451E.7CB2@cornell.edu>
References: <01bbe848$a6769820$cd2549c2 AT default>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0014.cit.cornell.edu
Mime-Version: 1.0
To: Thomas Harte <T DOT Harte AT btinternet DOT com>
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019