pointer->pointer problem

Wayne Throop throopw at sheol.UUCP
Mon Apr 8 10:25:56 AEST 1991


> reilly at bnlux1.bnl.gov (kevin reilly)
> [...whitespace squeezed for brevity...]
> main() { char **outPt; outPut = FUNC1(...); FUNC2(outPut); }
> char **FUNC1(...) { static char *lines[10]; /* do stuff */ return
>     &lines[0]; }
> void FUNC2(char **inPut) { /* If I manipulate the strings pointed to by
>     inPut in this function it seems other strings are also effected.  
>     Why is this? */ }

*What* strings pointed to by inPut?  These pointers have never been
initialized to point to anything.  (In fact, being static, they've
been initialized to point to *no*thing, and since nil pointers
often in "reality" point to the same non-place, this is likely
the cause of the aliasing observed.)

And while we're at it, isn't terribly wise to redeclare function
return types (from (int) to (char**) and from (int) to (void)).
It is likewise unwise to fail to return a value from "main".
--
Wayne Throop  ...!mcnc!dg-rtp!sheol!throopw



More information about the Comp.lang.c mailing list