problem with Data Files

C

CBFalconer

The C Standard has always required it to be sticky. Some (perhaps
even many) implementations still get it wrong.

On stdin from the keyboard? On disk files I agree.
 
A

Adrianp

If you want to know the value of EOF on your compiler look in stdio.h (or
whatever io lib you are using). eg

#define EOF (-1)

Mike Wahler said:
bhanu said:
Try this program: EOF is always -1,

It might be for a given compiler, it easily might not
be for others. The language imposes no requirement
that it be -1, only that it is an integer less than zero,
i.e. between INT_MIN and -1.

[snip code, which does not prove that EOF is always -1]

-Mike
 
M

Mike Wahler

Adrianp said:
If you want to know the value of EOF

But there isn't any *need* to know. And often this
(compiler-specific) 'knowledge' can lead one to write
code which has problems if it is ported to another
compiler (or another version of the same one).

This is the whole point of having abstractions such
as 'EOF'. They weren't created just for fun.
on your compiler look in stdio.h (or
whatever io lib you are using). eg

#define EOF (-1)

or #define EOF (-42)

etc.

But there's no need to look this up (and as I noted above,
doing so can lead the ignorant to write unnecessarily
nonportable code).

Just write EOF and you have a guarantee (from the language
standard), that every compliant compiler will create code
that works correctly.

BTW Please don't top-post in comp.lang.c

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top