TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BRIAN WOOD
from: ADAM MAJER
date: 1998-02-03 20:33:00
subject: more questions about new

BW>void Enlarge(char *p)
BW>{
BW>   char *x=new char[20];
BW>   delete[] p;
BW>   p=x;
BW>}
BW>void main()
BW>{
BW>   char *sz=new char[10];
BW>   Enlarge(sz);
BW>}
The sz _duplicate_ is pushed onto the stack and therefore the stack is
filled with the new address and not the sz variable in main.
BW>char *Enlarge(char *p)
BW>{
BW>   char *x=new char[20];
BW>   delete[] p;
BW>   return x;
BW>}
BW>void main()
BW>{
BW>   char *sz=new char[10];
BW>   sz=Enlarge(sz);
BW>}
BW>so far seems to work, but am I even on the right track?
This works since the x is returned in the DX:AX registers (16 bit) or
EDX:EAX registers for 32 bit code and then it is assiged to the sz
variable. :)
 * SLMR 2.1a * Back Up My Hard Drive? I Can't Find The Reverse Switch!
--- FMail 0.92
---------------
* Origin: The Programmer's Oasis on FIDONET! (1:348/203)

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