K
Keith Thompson
Charlie Gordon said:"Richard Bos" <[email protected]> a écrit dans le message de
(e-mail address removed)4all.nl... [...]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.
FILE may even be an incomplete type, there is no guarantee that a FILE *
properly cast to a char * can be safely dereferenced at all.
No, FILE cannot be an incomplete type. C99 7.19.1p2:
FILE
which is an object type capable of recording all the information
needed to control a stream [...]
I don't think think this requirement is necessary (i.e., the standard
could just as easily have allowed, or even required, FILE to be an
incomplete type without breaking any reasonable code), but there it
is.