Damian Walker
2015-02-08 13:09:58 UTC
Hello!
I'm returning to C programming after over a decade doing other things,
and I wanted to give Open Watcom a try. I want to write a simple
retro-game running under DOS, the target an 8088. But I've met a
setback pretty early.
I want to read a ~16k block into memory prior to doing other things with
it. I'm defining a static char array for the purpose, to the exact size
I want (16192 bytes). But whatever I do to get data into it--fread,
memset, setting individual elements--I get a "Stack Overflow!" Here's
the simplest code that creates the problem.
#include <stdio.h>
#include <stdlib.h>
int main() {
/* declarations */
char buffer [16192];
/* fill the buffer */
memset (buffer, 0, 16192);
/* finish the program */
return 0;
}
If I change the buffer size to 80, along with the appropriate parameter
in the call to memset(), the program runs without complaint. A more
complex example used fopen/fread to fill the buffer, with the same
results for 80 and 16192 bytes.
I've read the manual sections about memory models, and I'm using the
default small model. That's supposed to give me 64k of data with a
maximum size of 64k per variable. I can't find anything in the docs to
tell me why I can't have and use a single string of 16192 bytes.
I've ported this example to the old Personal C Compiler, which is my
other option for this project, and the program runs fine. But I'd
prefer to persevere with Watcom, as the documentation is better and it
adheres to ANSI.
Could someone please tell me what I'm doing wrong? Thanks!
I'm returning to C programming after over a decade doing other things,
and I wanted to give Open Watcom a try. I want to write a simple
retro-game running under DOS, the target an 8088. But I've met a
setback pretty early.
I want to read a ~16k block into memory prior to doing other things with
it. I'm defining a static char array for the purpose, to the exact size
I want (16192 bytes). But whatever I do to get data into it--fread,
memset, setting individual elements--I get a "Stack Overflow!" Here's
the simplest code that creates the problem.
#include <stdio.h>
#include <stdlib.h>
int main() {
/* declarations */
char buffer [16192];
/* fill the buffer */
memset (buffer, 0, 16192);
/* finish the program */
return 0;
}
If I change the buffer size to 80, along with the appropriate parameter
in the call to memset(), the program runs without complaint. A more
complex example used fopen/fread to fill the buffer, with the same
results for 80 and 16192 bytes.
I've read the manual sections about memory models, and I'm using the
default small model. That's supposed to give me 64k of data with a
maximum size of 64k per variable. I can't find anything in the docs to
tell me why I can't have and use a single string of 16192 bytes.
I've ported this example to the old Personal C Compiler, which is my
other option for this project, and the program runs fine. But I'd
prefer to persevere with Watcom, as the documentation is better and it
adheres to ANSI.
Could someone please tell me what I'm doing wrong? Thanks!
--
Damian Walker
Damian Walker