C questions

meissner at dg_rtp.UUCP meissner at dg_rtp.UUCP
Wed Feb 4 00:54:56 AEST 1987


In article <194 at olamb.UUCP> kimcm at olamb.UUCP (Kim Chr. Madsen) writes:
> 
> ... Just consider the example:
> 
> 	struct p {
> 		int	p_num;
> 		char	name[20];
> 		char	phone[12];
> 	} person;
> 
> 	while (read(fd,&person,sizeof(person)) == sizeof(person)) {
> 		...do something to person structure...
> 	}

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... */
	}

-- 
	Michael Meissner, Data General
	...mcnc!rti-sel!dg_rtp!meissner



More information about the Comp.lang.c mailing list