D
Douglas A. Gwyn
Richard said:On strcpy(), yes, but on fgets()? A char * and a FILE * can only overlap
if a. you're invoking UB anyway, by scribbling wildly into the FILE
object through a mispointed char *, or b. you're invoking UB anyway, by
scribbling neatly into the FILE object using undefined and unportable
assumptions about the layout of the FILE.
Um, no, consider fgets((char *)(void *)fp, (int)sizeof(FILE), fp);
while it may be a stupid thing to do, if no further use is made
of the associated stream it would have been allowed, and the
implementation would have to make it work, which means making
a copy of the FILE structure before starting the transfer.
By prohibiting overlap of the pointed-to objects, we assure
the implementor that he doesn't have to worry about that.