limitations of casts, pointer and function declarartions...

Mike Tilson mike at hcradm.UUCP
Tue Oct 30 01:32:17 AEST 1984


It was noted that C compilers do not accept the following:

	int x;
	char *y;

	(char *)x = y;

I assume that what is wanted is to treat storage location "x" as a cell
that holds a "char *".  Declaring "x" to be a union type is the portable
way to do this.  If one does not wish to be portable, C already allows
the type cast you want, but it's a bit more complicated:

	*( (char **) &x) = y;

I checked this on the Vax System V.2 compiler.  It likes it just fine, and
generates the obvious single instruction move.  Repeat: it isn't portable.



More information about the Comp.lang.c mailing list