Failure of "long x(cp) char * cp; { return *((long *) cp); }" is a bug?

Arthur David Olson ado at elsie.UUCP
Sun Jun 29 07:02:03 AEST 1986


As I understand it, the code produced by some compilers from

	long x(cp)
	char * cp;
	{
		return *((long *) cp);
	}

will cause core dumps if the value of cp isn't "appropriately aligned".
When dealing with such compilers, you get to do something like

	long x(cp)
	char * cp;
	{
		long l;

		function_to_do_arbitrary_copying((char *) &l, cp, sizeof l);
		return l;
	}

to avoid core dumps.

Isn't this really a compiler bug?  Doesn't the cast in the
		return *((long *) cp);
give the compiler all the evidence it needs that it should, *on its own*,
produce code that's the equivalent of the function call?

Does the latest version of X3J11 have anything to say on the matter?
--
Bug/s is a Volkswagen/Warner Brothers trademark.
--
	UUCP: ..decvax!seismo!elsie!ado		ARPA: elsie!ado at seismo.ARPA
	DEC, VAX, Elsie & Ado are Digital, Borden & Shakespeare trademarks.



More information about the Comp.lang.c mailing list