Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ames!dftsrv!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Okay, here's a toughie for you... (maybe) Message-ID: <28386@mimsy.umd.edu> Date: 7 Dec 90 19:34:00 GMT References: <2784@ux.acs.umn.edu> <386@moria.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 27 >In article <2784@ux.acs.umn.edu> edh@ux.acs.umn.edu (Eric D. Hendrickson) posts a large lump of code and asks why it crashes. In article <386@moria.UUCP> dcm@moria.UUCP (David C. Miller) writes: >You have 2 major problems: > 1. In extract() you are returning a pointer to an automatic variable. ... > 2. Also, found[] is not initialized. ... Doug Gwyn has pointed out a more fundamental error than either of these, namely, the type of the object being `returned' from extract and the type of the array `found' are entirely different. I doubt I will ever say this too often: You cannot, in C (as in many other languages), decide what a program fragment does until you both (A) know the types of all the expressions in that fragment are and (B) can show that they are mixed correctly. (If (B) fails, but you wrote the compiler or have equivalent knowledge, you can predict the machine's state anyway. This is useful for writing device drivers, but not for portable code.) Since the original program contains fundamental data-typing errors, it is impossible to say what it does. Once those are fixed (mentally if not actually), the two problems David Miller describes show up. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris