Mail Archives: djgpp/1997/03/01/15:39:07

From: aho450s AT nic DOT smsu DOT edu (Tony O'Bryan)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointer trouble... need help
Date: Sat, 01 Mar 1997 19:40:42 GMT
Organization: Southwest Missouri State University
Message-ID: <>
References: <5f9tk7$2mg AT nr1 DOT toronto DOT istar DOT net>
Lines: 33
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 1 Mar 1997 18:47:35 GMT, Jeff Weeks <pweeks AT execulink DOT com> wrote:

>I've got a structure:
>typedef struct { int h,c; } buf_data;
>and I define two variables and allocate memory for them:
>tbuf *buf_data;
>bbuf *buf_data;

I'm not very familar with C++.  However, the above two points (in C) 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?  Or am I
>totally wrong?  I've tried

tbuf = bbuf will merely have two pointers to the same memory.  This will not
copy the contents pointed to by bbuff into the memory allocated by new.  In
fact, the memory allocated by the second new will no longer be accessable at
all.  To copy memory blocks, the easiest way to is use one of the memory copy
functions such as memcpy(tbuf,bbuff,video.max_x);

- Raw text -

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