TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Paul Edwards
from: Bob Lawrence
date: 1996-11-10 08:45:20
subject: Special Requests

PE> void brilliant_function(char **p)
 PE> {
 PE> static char names[3][20] = { "bob", "rod",
"paul");
 PE> 
 PE> *p = names[2];
 PE> return;
 PE> }

 PE> int main(void)
 PE> {
 PE> char *n;
 PE> 
 PE> brilliant_function(&n);
 PE> printf("the brilliant person is %s\n", n);
 PE> return (0);
 PE> }

 PE> Well, as you can see, the caller is only declaring a pointer
 PE> himself. That pointer is pointing to some random location in
 PE> memory.

  Couldn't you have done the same thing by returning the pointer from
brilliant_function().. . or just pass (n) instead of (&n) and write
the data to that location?

  I'm not saying that you can't make it work with pointers to
pointers; just that I can't see any point in it. If you are going to
pass a pointer, then you may as well pass it back and use the one
pointer, or point it at the actual data rather than a pointer that
points to the data. It just seems to take an extra step for no reason.
Unless you used a typed pointer and wanted to mix them...

  Does a static array persist after the function has been called? If
not, you'll be pointing to phantom data. In Pascal, you have to make
it global outside the called function, or you lose it. And what
happens if you call it again? Does it make a new set of data in
memory? How does it know one "names" from the next one?

Regards,
Bob
___ Blue Wave/QWK v2.12
@EOT:

---
* Origin: Precision Nonsense, Sydney (3:711/934.12)
SEEN-BY: 711/934 712/610
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.