home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / std / c / 3002 < prev    next >
Encoding:
Text File  |  1992-11-13  |  931 b   |  39 lines

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.std.c
  4. Subject: fwrite+fread of pointer
  5. Message-ID: <15935@goanna.cs.rmit.oz.au>
  6. Date: 13 Nov 92 06:51:59 GMT
  7. Organization: Comp Sci, RMIT, Melbourne, Australia
  8. Lines: 29
  9.  
  10. I would like to know what the standard says about the following program:
  11.  
  12.     #include <stdlib.h>
  13.     #include <stdio.h>
  14.  
  15.     int main(argc, argv)
  16.         int argc;
  17.         char **argv;
  18.         {
  19.         char dummy;
  20.         char *p;
  21.         FILE *f;
  22.  
  23.         f = fopen("WORK", "w+b");
  24.         p = &dummy;
  25.         fwrite(&p, sizeof p, 1, f);
  26.         rewind(f);
  27.         fread(&p, sizeof p, 1, f);
  28.         fclose(f);
  29.         printf("%d\n", p == &dummy);
  30.         exit(0);
  31.         }
  32.  
  33. In order to save space I have omitted to test the results of fopen(),
  34. fwrite(), and fread(), tests which I would not omit in practice.
  35.  
  36. What I want to know is whether, assuming nothing else goes wrong, the
  37. program _must_ print 1 or whether it may print 0.
  38.  
  39.