Mail Archives: djgpp/1997/12/29/21:18:03
Rune Lanton wrote:
>
> I wrote this little program in DJGPP, or at least I tried, but
> something went wrong!!!!
for your own benefit, i would recommend using ANSI prototypes.
> This code you see here works just fine when I try to read small files,
> less than 1000 bytes I think, but when I try to read bigger files it
> doesn't work.
> WHY!!!!!!!
>
> Here's the code:
>
> #include <stdio.h>
>
> void main(arg_counter, arg_pointers)
> int arg_counter;
> char *arg_pointers[];
like, using int main(int argc, char *argv[]) here would not hurt. there
is no guarantee that the non-ANSI style will continue to work. in any
case, i did not compile your program but your problem probably has to do
with file_buffer. file_buffer is an unitialized pointer. below, you do:
> *file_buffer = malloc((file_size)+512);
which converts the pointer returned by malloc into int (because you did
not include <stdlib.h> where malloc is declared. if you had done that
and turned on -Wall, you would have known about this) and writes these
four bytes into some unknown location depending on the value of
file_buffer (which you have not initialized.) that probably causes a
segmentation violation at random times.
if you had initialized file_buffer to NULL to begin with, and were
running under dos with cwsdpmi as your dpmi server, you would have
caught this error easily.
hth.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -