Date: Fri, 1 Nov 1996 18:01:30 -0500 Message-Id: <199611012301.SAA14260@delorie.com> From: DJ Delorie To: indrek AT warp DOT edu DOT ee CC: djgpp AT delorie DOT com In-reply-to: (message from Indrek Mandre on Fri, 1 Nov 1996 21:06:13 +0200 (EET)) Subject: Re: Problems with fread/fwrite > > The bugs are not in DJGPP, but rather in some wrong assumptions you are > > making about the way memory and file handling is done in C. > > Yes, I'v never programmed on DOS, but I have correct assumptions. You assume that text files and binary files are interchangeable. ANSI states that you may not make that assumption. > Well, I have only 1 thing to say and think: DOS _is_ stupid. No, DOS is *different*. Both DOS and Unix are ANSI compliant, if you pay attention to what ANSI states you may assume and not assume. > I thougt that djgpp is like gcc. But now I know - djgpp is not gcc. DJGPP *includes* gcc, it is not "like" gcc. It uses gcc unmodified. However, your problem has nothing to do with gcc, it has to do with the C library, which is ANSI compliant. Your program is NOT compliant. > Djgpp is stupid???? No, you are not programming according to the ANSI specs. > Wrong! It's only because of the fopen/fread. Since your data is uninitialized, it's likely that text/binary conversions will take place, as it's likely that some of those characters are newlines. > I'm not using ANSI C. I think djgpp is _not_ ansi c. You are not *writing* ANSI C, and DJGPP *is* ANSI C. That is the problem. If you had been writing ANSI C, your program would have worked. > I'v reed only one book - Kerninghan-Ritchie's "The C programming > language". My programming is based on that. There was no need to > zero variables. You should obtain the second edition to that book, which is based on ANSI C instead of the obsolete K&R C. There is no need to zero out global variables. You must initialize stack variables. This is stated in the ANSI spec. > I'm not so stupid. What are these text mode commands? If you open the file with 'fopen(..., "r")', you have issued a text-mode open, so all your fread/fwrite functions will be doing text-mode I/O. > > Try running under a debugger (gdb, edebug32, fsdb) and examine the contents > > of those variables after you declare them. You'll see what I mean. > > Well, I was born using debugger :) That would, according to DJGPP's history, make you less than five years old :-) > No, void main ( void ) is! I'm right. You are right. In gcc there is no > difference, or is there? Explain me please. Nowhere is said what is correct. main() must return an integer return value, according to ANSI C.