From: kagel AT quasar DOT bloomberg DOT com Date: Mon, 23 Dec 1996 14:04:22 -0500 Message-Id: <9612231904.AA22932@quasar.bloomberg.com > To: T DOT Harte AT btinternet DOT com Cc: djgpp AT delorie DOT com In-Reply-To: <01bbe862$3b6f2780$312549c2@default> (T.Harte@btinternet.com) Subject: Re: More malloc troubles Reply-To: kagel AT dg1 DOT bloomberg DOT com From: "Thomas Harte" Date: 12 Dec 1996 19:33:22 GMT All right, thanks to all those who helped me last time, but I'm still having problems. In DJGPP, before main(), I declare these variables as global:- unsigned char *vbuf ; unsigned char *doublebuffer ; unsigned char *background ; Then, soon as the program starts, I do this :- unsigned char *vbuf = (unsigned char *)malloc(64000); unsigned char *doublebuffer = (unsigned char *)malloc(64000); unsigned char *background = (unsigned char *)malloc(64000); But, it causes a general protection fault every single time! I know I am in-experienced, but surely there is something seriously wrong here? It compiles without errors but brings down DOS every single time. Once again, thanking people in advance, If by 'as soon as the program starts' you mean inside main() then there is the problem. You have declared local variables vbuf, doublebuffer, & background the same names as the globals and initialized them then you probably tried to access the global pointers which were never initialized. Remove the declarations in main() and just initialize the existing variables: /* Global Variables -- BTW I hate globals (and will gladly expound on why)! */ unsigned char *vbuf; unsigned char *doublebuffer; unsigned char *background; int main( void ) { /*local declarations*/ ::: vbuf = (unsigned char *)malloc(64000); doublebuffer = (unsigned char *)malloc(64000); background = (unsigned char *)malloc(64000); /* more code */ ::: return 0; } -- Art S. Kagel, kagel AT quasar DOT bloomberg DOT com A proverb is no proverb to you 'till life has illustrated it. -- John Keats