Okay, here's a toughie for you... (maybe)

Chris Torek chris at mimsy.umd.edu
Sat Dec 8 06:34:00 AEST 1990


>In article <2784 at ux.acs.umn.edu> edh at ux.acs.umn.edu
 (Eric D. Hendrickson) posts a large lump of code and asks why it crashes.

In article <386 at moria.UUCP> dcm at 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 at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list