Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!oddjob!gargoyle!ihnp4!alberta!ers!teletron!andrew From: andrew@teletron.UUCP (Andrew Scott) Newsgroups: comp.lang.c Subject: pointer cast question Message-ID: <100@teletron.UUCP> Date: Tue, 15-Sep-87 15:57:00 EDT Article-I.D.: teletron.100 Posted: Tue Sep 15 15:57:00 1987 Date-Received: Sun, 20-Sep-87 03:00:35 EDT Organization: TeleTronic Communications Ltd., Edmonton, Alta. Lines: 16 Keywords: pointer cast alignment I am curious as to why pointer casts behave the way they do. Specifically, casting from a pointer to one type to a pointer to another type may cause address exceptions if the alignment requirements of the two types differ (as described in section 14.4 of K&R). Thus, it is the programmer's responsibility to insure that the pointers involved in such expressions point to valid addresses after the cast. Why is this the case? It seems to me that the cast should produce code which aligns the pointer to a proper alignment boundary if necessary. The compiler should hide such a machine dependant thing from the programmer. What is the purpose of such a cast (other than to make lint happy) if not to convert a valid data value of one type to a valid data type of another? Does anybody have any answers? Andrew