TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRISTIAN S. PEDERSEN
from: FRANOIS DE MEY
date: 1997-07-28 02:47:00
subject: Conversion of pointer.

Hi coder...
 CSP> int* test()
 CSP> {
 CSP> int i=5;
 CSP> return &i;
 CSP> }
 CSP> Why do I get a "Suspicious pointer conversion"-warning ? The functions
 CSP> using this concept seems to work OK. Should I make them differently. 
 Because, in this function, he allocate dynamically 'i', this means that,
 when U get out of this function, i won't exist. If the result is wright,
 that means that i is no more known as a variable, but it contents didn't
 change. Look at this, I don't know if it would work as I say, but I suppose.
 int* IPtr;
 IPtr = test();
 int IntValue1;
 int IntValue2;
 IntValue2 = 18;
 Here, i'm not for cent per cent certain, but i believe *IPtr would be 18.
 For explaination, look at pile on each line.
 int* IPtr;
*0000=???? -> IPtr
 0004=???? -> Nothing
 0008=???? -> Nothing
 000C=???? -> Nothing
 IPtr = test();
 0000=???? -> IPtr
*0004=xxxx -> Return adress of Test
 0008=???? -> Nothing
 int i = 5;
 
 0000=???? -> IPtr
 0004=xxxx -> Return adress of Test
*0008=0005 -> i
 return &i;
*0000=0008 -> IPtr
 0004=xxxx -> Return adress of Test
 0008=0005 -> i
 N.B.: AX = &i. ( here, 0008 ), then ax will be put in IPtr.
 int IntValue1;
 0000=0008 -> IPtr
*0004=xxxx -> IntValue1 will contain ex-return adress of Test
 0008=0005 -> i
 int IntValue2;
 0000=0008 -> IPtr
 0004=xxxx -> IntValue1
*0008=0005 -> IntValue2 will contain ex-i
 IntValue2 = 18;
 0000=0008 -> IPtr
 0004=xxxx -> IntValue1
*0008=0018 -> IntValue2
 IPtr = (here)0008 => IPtr = *IntValue2
 cqfd
Ciao
                        Ÿäâ
 -I hope it will be useful 2 U.-
... Coding is so funny...
--- Blue Wave/DOS v2.30 [NR]
---------------
* Origin: Programmer's Paradise -Belgium- 32-10-813088 (2:293/2009)

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