Programming in standard c
- From: jacob navia <jacob@xxxxxxxxxx>
- Date: Wed, 26 Dec 2007 21:54:27 +0100
In my "Happy Christmas" message, I proposed a function to read
a file into a RAM buffer and return that buffer or NULL if
the file doesn't exist or some other error is found.
It is interesting to see that the answers to that message prove that
programming exclusively in standard C is completely impossible even
for a small and ridiculously simple program like the one I proposed.
1 I read the file contents in binary mode, what should allow me
to use ftell/fseek to determine the file size.
No objections to this were raised, except of course the obvious
one, if the "file" was some file associated with stdin, for
instance under some unix machine /dev/tty01 or similar...
I did not test for this since it is impossible in standard C:
isatty() is not in the standard.
2) There is NO portable way to determine which characters should be
ignored when transforming a binary file into a text file. One
reader (CB Falconer) proposed to open the file in binary mode
and then in text mode and compare the two buffers to see which
characters were missing... Well, that would be too expensive.
3) I used different values for errno defined by POSIX, but not by
the C standard, that defines only a few. Again, error handling
is not something important to be standardized, according to
the committee. errno is there but its usage is absolutely
not portable at all and goes immediately beyond what standard C
offers.
We hear again and again that this group is about standard C *"ONLY"*.
Could someone here then, tell me how this simple program could be
written in standard C?
This confirms my arguments about the need to improve the quality
of the standard library!
You can't do *anything* in just standard C.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.
- Follow-Ups:
- Re: Programming in standard c
- From: Paul Hsieh
- Re: Programming in standard c
- From: Ravishankar S
- Re: Programming in standard c
- From: Mark McIntyre
- Re: Programming in standard c
- From: Malcolm McLean
- Re: Programming in standard c
- From: Stephen Montgomery-Smith
- Re: Programming in standard c
- From: Julienne Walker
- Re: Programming in standard c
- From: user923005
- Re: Programming in standard c
- From: Eric Sosman
- Re: Programming in standard c
- From: jameskuyper
- Re: Programming in standard c
- From: Flash Gordon
- Re: Programming in standard c
- From: Walter Roberson
- Re: Programming in standard c
- From: Walter Roberson
- Re: Programming in standard c
- Prev by Date: Re: Making C better (by borrowing from C++)
- Next by Date: Re: Making C better (by borrowing from C++)
- Previous by thread: question about void typecast
- Next by thread: Re: Programming in standard c
- Index(es):
Relevant Pages
|