Article View: comp.std.c
Article #4835fread/fwrite [was Re: sizeof(char) ~= sizeof(float)]
From: Nick Maclaren
Date: Tue, 27 Feb 1996 19:40
Date: Tue, 27 Feb 1996 19:40
30 lines
2044 bytes
2044 bytes
In article <DnFr78.1wo@ukpsshp1.serigate.philips.nl>, Stephen Baynes <baynes@ukpsshp1.serigate.philips.nl> wrote: >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote: >: In article <4gr3d1$dca@usenet.pa.dec.com> >: diamond@tbj.dec.com (Norman Diamond) writes: ><snip - copying data by using chars of different sorts vs memcpy > >: This was a free-standing implementation, and memcpy may be absent. (In >: a hosted implementation, as all read/write is done as if through >: getc/putc which handles unsigned char values, and binary files written >: out must be read back unchanged, the situation is impossible). > >That read/write is done by getc/putc does not imply very much about copying >chars. I don't see any requirement that fwrite/fread use one putc/getc per >byte(ie char) of memory. Fwrite could use one per bit writing the values 'Y' or >'N' if it wanted so long as fread will read it back again. My understanding >is that the use of getc/putc means you can write a file with fwrite, copy it >with getc/putc and read the copy with fread to get what you started with. Not quite. You must either do ALL I/O as text or ALL as binary! This isn't stated by the standard, but fread and fwrite are unimplementable if it is not true. I would prefer them to be forbidden on text files, or at least implementation defined. Nick Maclaren, University of Cambridge Computer Laboratory, New Museums Site, Pembroke Street, Cambridge CB2 3QG, England. Email: nmm1@cam.ac.uk Tel.: +44 1223 334761 Fax: +44 1223 334679
Technical Details
Message-ID:
<4gvmmn$6tf@lyra.csx.cam.ac.uk>Path:
arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1References:
<WALD.96Feb24131532@woodpecker.lcs.mit.edu> <4gr3d1$dca@usenet.pa.dec.com> <TANMOY.96Feb25203514@qcd.lanl.gov> <DnFr78.1wo@ukpsshp1.serigate.philips.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1 From: nmm1@cus.cam.ac.uk (Nick Maclaren) Newsgroups: comp.std.c Subject: fread/fwrite [was Re: sizeof(char) ~= sizeof(float)] Date: 27 Feb 1996 19:40:07 GMT Organization: University of Cambridge, England Message-ID: <4gvmmn$6tf@lyra.csx.cam.ac.uk> References: <WALD.96Feb24131532@woodpecker.lcs.mit.edu> <4gr3d1$dca@usenet.pa.dec.com> <TANMOY.96Feb25203514@qcd.lanl.gov> <DnFr78.1wo@ukpsshp1.serigate.philips.nl> NNTP-Posting-Host: bootes.cus.cam.ac.uk