Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!mit-eddie!cybvax0!frog!john From: john@frog.UUCP (John Woods, Software) Newsgroups: net.lang.c Subject: Re: Failure of "long x(cp) char * cp; { return *((long *) cp); }" is a bug? Message-ID: <940@frog.UUCP> Date: Tue, 1-Jul-86 12:57:23 EDT Article-I.D.: frog.940 Posted: Tue Jul 1 12:57:23 1986 Date-Received: Thu, 3-Jul-86 19:30:58 EDT References: <6152@elsie.UUCP> Organization: Superfrog Heaven [ CRDS, Framingham MA ] Lines: 30 > 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? No, I'd say not. The compiler is doing just exactly what you said in the first case. What you said was something stupid, ergo it does something stupid. Lint will complain about the construction, declaring there to be a "possible pointer alignment problem" (you bet!). (by the way, an in-line copy would be faster than the function call (except perhaps on machines where function calls take negative time :-) )). -- John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101 ...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA "Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time with computers, and nobody thinks of complaining." Jeff Raskin, interviewed in Doctor Dobb's Journal