home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!goanna!ok
- From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
- Newsgroups: comp.std.c
- Subject: fwrite+fread of pointer
- Message-ID: <15935@goanna.cs.rmit.oz.au>
- Date: 13 Nov 92 06:51:59 GMT
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Lines: 29
-
- I would like to know what the standard says about the following program:
-
- #include <stdlib.h>
- #include <stdio.h>
-
- int main(argc, argv)
- int argc;
- char **argv;
- {
- char dummy;
- char *p;
- FILE *f;
-
- f = fopen("WORK", "w+b");
- p = &dummy;
- fwrite(&p, sizeof p, 1, f);
- rewind(f);
- fread(&p, sizeof p, 1, f);
- fclose(f);
- printf("%d\n", p == &dummy);
- exit(0);
- }
-
- In order to save space I have omitted to test the results of fopen(),
- fwrite(), and fread(), tests which I would not omit in practice.
-
- What I want to know is whether, assuming nothing else goes wrong, the
- program _must_ print 1 or whether it may print 0.
-
-