TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRISTIAN S. PEDERSEN
from: ERIK WARMELINK
date: 1997-08-07 22:08:00
subject: Re: Conversion of pointe

Christian, 31 Jul Anthony Tibbs wrote to you:
 AT>  Try this:
 AT>  int *test (void);
 AT>  
 AT>  int main (void)
 AT>  {
 AT>  int *value;
 AT>  
 AT>    value = test;
test is a pointer to function returning an int pointer, not a pointer to an 
int. Perhaps Anthony meant ``test()'' instead of ``test''.
 AT>    printf ("The value of \"value\" is: %d\n",value);
value is a pointer to an int, not an int as %d in the format string suggests.
 AT>    return 0;
 AT>  }
 AT>  int *test (void)
 AT>  {
 AT>    int *i = 5;
5 is an int, not a pointer to an int.
 AT>    return &i;
&i is a pointer to a pointer to an int, not a pointer to an int. Returning a 
pointer to a local non-static variable is always bad. Well perhaps 'always' 
is too strong: "Nothing is completely true, not even this", Multatuli ;-)
 AT>  }
 AT>  
 AT>  Since printf() uses quite a bit of stack space in its
 AT> operations, you  can be pretty sure that "value" will not be
 AT> 5 when you check.  
That's true. ;-)
To Anthony: you should really compile example code you post, preferrably with 
all warnings turned on.
Bye,
 Erik 
---
---------------
* Origin: WarmelinkE@vertis.nl (2:282/1.60)

SOURCE: echomail via exec-pc

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™.