* DEC C Weirdness
@ 1996-07-12 4:00 James L. Heid
1996-07-16 4:00 ` Duane Smith
0 siblings, 1 reply; 2+ messages in thread
From: James L. Heid @ 1996-07-12 4:00 UTC (permalink / raw)
This happened to me on OpenVMS VAX V6.1 running DEC C V5.0-003
There is a real application behind all this, but I will post the results of a
test in the hope that someone can explain what is happening.
I have a file that has non-printable characters in it. Using the dump utility
I can tell that one particular 3 byte sequence looks like this (after putting
it in left-to-right format) 00ff7f.
I wrote a program that opens the input file and an output file and does the
following:
while ((c = fgetc(fp) != EOF)
putc(c, outfile);
That's all... just that. I expected, therefore, that I would create an
identical file and I would still find this 3-byte sequence where it was
before. However, what I found instead in place of this sequence was the
linefeed byte, 0a. This sequence occurs 2 times in the file, and both times
this happens.
Can someone explain this to me?
Jim Heid
Los Alamos National Laboratory
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: DEC C Weirdness
1996-07-12 4:00 DEC C Weirdness James L. Heid
@ 1996-07-16 4:00 ` Duane Smith
0 siblings, 0 replies; 2+ messages in thread
From: Duane Smith @ 1996-07-16 4:00 UTC (permalink / raw)
To: James L. Heid; +Cc: d_smith, "quarry::mario"
James L. Heid wrote:
>
> This happened to me on OpenVMS VAX V6.1 running DEC C V5.0-003
>
> There is a real application behind all this, but I will post the results of a
> test in the hope that someone can explain what is happening.
>
> while ((c = fgetc(fp) != EOF)
> putc(c, outfile);
>
The precedence of "!=" is higher than that of "=" which means that
the evaluation order will be:
while ( c = (fgetc(fp) != EOF) )
While the test for EOF will work okay, the assignment will be whatever
the inequality results are. Try adding parens:
while ( (c = fgetc(fp)) != EOF )
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-07-16 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-07-12 4:00 DEC C Weirdness James L. Heid
1996-07-16 4:00 ` Duane Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox