Mail Archives: djgpp/1996/12/23/14:36:30
From: "Thomas Harte" <T DOT Harte AT btinternet DOT com>
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
- Raw text -