C questions
kimcm at olamb.UUCP
kimcm at olamb.UUCP
Thu Feb 12 22:00:56 AEST 1987
In article <954 at dg_rtp.UUCP>, meissner at dg_rtp.UUCP (Michael Meissner) writes:
] In article <194 at olamb.UUCP> kimcm at olamb.UUCP (Kim Chr. Madsen) writes:
] ] [Some code of mine...]
]
] Let's indead consider this example. This is wrong, wrong, wrong (even
] though it may happen to work on your system). The second argument to
] read is a char *, not a structure pointer. To pass lint (and to have
] it work on word-based machines), it should read:
]
] /* ... */
]
] while (read(fd, (char *) &person,sizeof(person)) == sizeof(person)) {
] /* ...do something to person structure... */
] }
Well, I made a mistake, I wrote the code on the spot and forgot to cast the
struct pointer to a char pointer. Yes I know they have different types, but
that doesn't make the example (of proving sizeof as essential knowledge to
a C programmer) invalid.
Kindly Regards
Kim Chr. Madsen
More information about the Comp.lang.c
mailing list