HELP:Pointers in function arguement 
Author Message
 HELP:Pointers in function arguement

(initialization deleted)
: void crossover(...., ...., unsigned long **c1, unsigned long **c2)
: {
:       unsigned long x,y;
:      
:       *c1 = &x;
:       *c2 = &y;

You should know that x and y are allocated with a scope that is only
within crossover. When you take the address of x or y (&x &y) it is only
valid within the crossover function. When crossover terminates, your
assignments are not meaningful and will not produce correct results. I'm
suspecting that you should call crossover with (..., ..., c1, c2) and
then within crossover assign *c1 = x and *c2 = y. That will copy the
value of x to the bytes allocated by your mem(sizeof(unsigned long)) area.
--



Sun, 06 Jul 1997 00:46:38 GMT  
 HELP:Pointers in function arguement
|> (initialization deleted)
|> : void crossover(...., ...., unsigned long **c1, unsigned long **c2)
|> : {
|> :         unsigned long x,y;
|> :        
|> :         *c1 = &x;
|> :         *c2 = &y;
|>
|> You should know that x and y are allocated with a scope that is only
|> within crossover. When you take the address of x or y (&x &y) it is only

Let us keep terminology straight here. What you are talking about is lifetime or
duration not scope. `static unsigned long x, y; would also have the same _scope_,
but then you could correctly return c1 and c2.

|> valid within the crossover function. When crossover terminates, your
|> assignments are not meaningful and will not produce correct results. I'm
|> suspecting that you should call crossover with (..., ..., c1, c2) and
|> then within crossover assign *c1 = x and *c2 = y. That will copy the
|> value of x to the bytes allocated by your mem(sizeof(unsigned long)) area.

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Sun, 06 Jul 1997 02:59:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Return pointer to function as arguement.

2. non-novice needs help with variable arguements va_arg to a function

3. How to use (pointer to function), and function and pointer to (pointer to function)

4. Pointer Functions and Pointers to Pointer Functions

5. Functions using variable arguements

6. default values for function arguements possible?

7. size of array as function arguement ?

8. size of array as function arguement ?

9. problems with GRAY_BRUSH as arguement for GetStockObject() function...

10. Pointer to an array of function pointers [HELP!]

11. HELP: function prototype with pointer to function as parameter

12. Help with an arguement

 

 
Powered by phpBB® Forum Software