delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/01/19:23:43

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointer trouble... need help
Date: Sat, 01 Mar 1997 14:58:38 -0800
Organization: Alcyone Systems
Lines: 38
Message-ID: <3318B49E.78D96981@alcyone.com>
References: <5f9tk7$2mg AT nr1 DOT toronto DOT istar DOT net>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jeff Weeks wrote:

> typedef struct { int h,c; } buf_data;
    ...
> tbuf *buf_data;
> bbuf *buf_data;

This should be 

    buf_data *tbuf;
    buf_data *bbuf;

> tbuf = new buf_data[video.max_x];
> bbuf = new buf_data[video.max_x];
> 
> and now I want to copy the values from bbuf to tbuf.  The following
> should work shouldn't it?
> 
> tbuf = bbuf;
> 
> because it would copy the address of bbuf into tbuf right?

Are you trying to copy the pointers or copy _what bbuf_ is pointing to into
what tbuf is pointing to?

If it's the former, then the above is correct, but now what tbuf was
originally pointing to is lost (you have no more references to it).  If you
want to copy what is being referenced by those pointers, then you need 

    memcpy(tbuf, bbuf, video.max_x*sizeof(buf_data));

-- 
       Erik Max Francis, &tSftDotIotE / email:  max AT alcyone DOT com
                     Alcyone Systems /    web:  http://www.alcyone.com/max/
San Jose, California, United States /    icbm:  37 20 07 N  121 53 38 W
                                   \
              "I am become death, / destroyer of worlds."
                                 / J. Robert Oppenheimer (quoting legend)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019