fwrite man page "error" 
Author Message
 fwrite man page "error"

Here's a cute one.
I had a user come to me asking about fread/fwrite,
showing me the man page:

    standard fread() man page "SYNTAX" section:

         fread(ptr, sizeof(*ptr), nitems, stream)
         char *ptr; unsigned nitems, sizeof(*ptr)
         FILE *stream;

Pointing to "sizeof(*ptr)" then to "char *ptr", he asked
        "but won't that always be one?"

I never noticed the "error" -- sort of cute, eh?
I can just imagine a novice user sitting with the man page
and pounding at the program wondering why it doesn't work!

I offered that the following might be better:

---------------vvvvvvv
         fread((char*)ptr, sizeof(*ptr), nitems, stream)
         item *ptr; unsigned nitems, sizeof(*ptr)
---------^^^^
         FILE *stream;

which seems to make things more clear.  I left it at that.
I suppose I should tell him that sizeof(char) is !always 1, though.

        *jeff*

------------------------------------------------------------------------------
Jeffrey Eric Francis Friedl                             Box 2173 Babcock House
..!{uunet,decvax}!unh!jeff                          Durham New Hampshire 03824

Ever worked in Japan? Let me know your "what-to-do, what-never-to-do" stories.
I'm moving there in May (or so -- whenver the Visa comes through).



Mon, 20 Jul 1992 05:55:00 GMT  
 fwrite man page "error"

Quote:
> I suppose I should tell him that sizeof(char) is !always 1, though.

It's not?  The Bible, second edition, A7.4.8 (page 204), third
sentence:

        When sizeof is applied to a char, the result is 1; [...].

I think the first edition contained something similar, though I'm not
sure.  Do you know of any compilers which disagree?

                                        der Mouse

                        old: mcgill-vision!mouse



Mon, 17 Aug 1992 09:03:00 GMT  
 fwrite man page "error"

Quote:


>> I suppose I should tell him that sizeof(char) is !always 1, though.
>    When sizeof is applied to a char, the result is 1; [...].
>I think the first edition contained something similar, though I'm not
>sure.  Do you know of any compilers which disagree?

K&R 1st Ed. Appendix A, generally taken as the de facto pre-ANSI C
standard, says that the units of sizeof are bytes, undefined by the
C language.  It also notes that in all existing (meaning AT&T) C
implementations byte and char are essentially synonymous.

The proposed ANSI C standard officially requires the identity between
the byte (sizeof unit) and the space used to hold a char.  There is
apparently a LOT of existing code that relied on that non-guaranteed
property, so X3J11 decided it would be a useful service to guarantee
it.  (I argued against that, for reasons posted to this newsgroup
some time ago.)



Mon, 17 Aug 1992 02:28:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. "In Page" Error

2. Error "free"-ing "malloc"-ed memory

3. fwrite and "bad address" message

4. Deleting with "fwrite()"

5. Man page for Berkeley's "error" on uunet.

6. Compile error "Internal error during SetupPhase"

7. "Page Printer" window

8. Help "Lost Web page"

9. Win 98 "Invalid Page Fault", works fine on W2K, NT

10. Programmatically setting "pages per sheet"

11. "Find in page" in CHtmlView

12. Wizard Pages and "?"

 

 
Powered by phpBB® Forum Software