Article View: comp.std.c
Article #2101fwrite+fread of pointer
From: Richard A. O'Keefe
Date: Fri, 13 Nov 1992 06:51
Date: Fri, 13 Nov 1992 06:51
28 lines
967 bytes
967 bytes
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.
Technical Details
Message-ID:
<15935@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!goanna!okShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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