Re: msvcrt fflush bug?

From: Severian (severian_at_chlamydia-is-not-a-flower.com)
Date: 12/09/04


Date: Thu, 09 Dec 2004 13:15:08 GMT

On Wed, 8 Dec 2004 17:09:02 -0800, "brad"
<brad@discussions.microsoft.com> wrote:

>According to the K&R ANSI C book, when using fopen to open a file in
>read/write mode you are supposed to either flush or seek the file when
>switching from reading to writing or vice versa.
>
>Unfortunately msvcrt's fflush does not seem to do the job. In the example
>code below, add or remove the #SHOW_BUG define to see the different
>behaviors. Is this indeed a bug? What's the best way to report it?

You seem to have provided a relatively complete example, as long as it
compiles and runs according to your claims. I have not tested on my
systems (since I don't know how closely my environments resemble
yours). I spun my brain reading the standard for a while, but I can't
produce a conclusive answer.

A few notes:

1) You include "stdio.h", but system includes should be in angle
brackets: <stdio.h>. "" and <> includes could come from different
locations, depending on your specific compiler settings. This may not
be relevant, but should be fixed.

2) You should post standard C questions where standard C experts know
about them; Microsoft newsgroups are generally not the right place --
they tend to concentrate on Microsoft-specific code. I would recommed
comp.lang.c, after compiling correctly: ANSI standard C code (disable
MS extenstions, enable ANSI mode, and be sure you're not using the
C++ compiler).

3) If you still see the apparent problem, verify it at comp.lang.c
before submitting to Microsoft; the experts know their stuff inside
and out.

4) They may ask you what an _IOREAD flag is, since it is (AFAIK)
implementation-specific.

5) Being tired and old, I may have missed something obvious. Should
you learn so, feel free to ridicule me.

...code snipped...

PS. There are many things that could cause such a problem; for one, if
you're running a beta or old version of your development environment,
be sure to compare your resluts to a current and official release. And
make sure the C runtime libraries are up-to-date on your system; for
best results, link with the non-DLL runtimes from the SDK. Linking
with DLL runtimes can cause problems when other application
installations replace the correct DLLs.

Damn, that was a lot of PS. Programming for any specific environment
is a bitch (especially Windows)!

--
Sev

Loading