Help me cast this!

Carl Paukstis carlp at iscuva.ISCS.COM
Wed May 4 09:38:46 AEST 1988


In article <294 at fedeva.UUCP> wrd3156 at fedeva.UUCP (Bill Daniels) writes:
=
=How do I cast the malloc() in line 12 of the following program to avoid 
=the lint cries of "warning: illegal pointer combination" et al?
=
=#include <stdio.h>
=
=main()	
={
=	char *malloc();
=	int i;
=	struct outfile {
=		int j;
=		int k;
=	} (*output)[];
=
=	output = malloc(sizeof(struct outfile) * 3);
=
=	(*output)[0].j = 1;
=	(*output)[0].k = 2;
=
=	i = printf("%d   %d\n",(*output)[0].j,(*output)[0].k);
=
=	return(i);
=}
=-- 
=bill daniels
=federal express, memphis, tn
={hplabs!csun,gatech!emcard}!fedeva!wrd3156

	output = (struct outfile **)malloc(sizeof(struct outfile) * 3);

works on Ultrix 2.something, a Sys V "compliant" type system complains of
"possible pointer alignment problem", presumably because "char" requires
only byte alignment (returned from malloc), while "struct outfile *"
requires halfword alignment (on 68010 systems).  Maybe my lint is too
good... I can't find a combination that passes clean on the Sys V system,
either.
-- 
Carl Paukstis    +1 509 927 5600 x5321  |"I met a girl who sang the blues
                                        | and asked her for some happy news
UUCP:     carlp at iscuvc.ISCS.COM         | but she just smiled and turned away"
          ...uunet!iscuva!iscuvc!carlp  |                    - Don MacLean



More information about the Comp.lang.c mailing list