public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Ian Williams <ianw@sgi.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: RE: c++/2892
Date: Tue, 29 May 2001 10:56:00 -0000	[thread overview]
Message-ID: <20010529175601.3983.qmail@sourceware.cygnus.com> (raw)

The following reply was made to PR c++/2892; it has been noted by GNATS.

From: Ian Williams <ianw@sgi.com>
To: "'nathan@gcc.gnu.org'" <nathan@gcc.gnu.org>
Cc: gcc-gnats@gcc.gnu.org, Ian Williams <ianw@sgi.com>,
        Keith Seto
	 <keith@sgi.com>, nobody@gcc.gnu.org
Subject: RE: c++/2892
Date: Tue, 29 May 2001 10:54:02 -0700

 Apologies for replying all, however, i'm not sure how to replace the source
 file without creating a new bug so i've attached the corrected example
 program source at the bottom of this mail.
 
 (I think the original one got messed up as a result of some transfer to/from
 my Windows based mail system).
 
 Let me know if you would prefer me to send the program via another method.
 
 Thanks,
 
 Ian.
 
 
 -----Original Message-----
 From: nathan@gcc.gnu.org [ mailto:nathan@gcc.gnu.org ]
 Sent: Monday, May 28, 2001 3:15 AM
 To: gcc-gnats@gcc.gnu.org; ianw@sgi.com; keith@sgi.com;
 nobody@gcc.gnu.org
 Subject: Re: c++/2892
 
 
 Synopsis: array addresses corrupted when using template classes
 
 State-Changed-From-To: open->feedback
 State-Changed-By: nathan
 State-Changed-When: Mon May 28 03:14:57 2001
 State-Changed-Why:
     the sample code provided is full of strang \par things.
     please proved corrected sample code
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2892&database=gcc
 
 
 
 
 
 --------------------------------------------------------------
 
 
 /*	Compile:        g++ -o test test.c++	*/
 
 #include <string.h>
 #include <iostream.h>
 #include <fstream.h>
 #include <stdlib.h>
 
 #ifndef TRUE
 #define TRUE    1
 #endif
 
 #ifndef FALSE
 #define FALSE   0
 #endif
 
 template <class T, class F> // T="To" the storage format for the buffer
                                 // F="From", the storage format from which
 the
                                 //           data comes
 
 
 class Buffer
 {
 public:
 
         Buffer(int length=100, char* label=NULL);
         virtual ~Buffer();
 
         virtual bool    add(F item) = 0;
         T*                      buf() const;
         int                     bufLength() const;
         bool                    canAddTo();
         void                    reset();
 
 protected:
 
         T*              mBuffer;
         int             mInBuffer;
 
 private:
 
         Buffer(const Buffer<T,F>& b);
 
         int     mBufferLength;
         bool    mOverflowReported;
         char*   mBufferName;
 };
 
 template <class T, class F>
 Buffer<T,F>::Buffer(int length, char* label) :
                 mBufferLength(length), mOverflowReported(FALSE),
                 mBuffer(NULL), mInBuffer(0), mBufferName(NULL)
 {
         mBuffer = new T[length];
         if (label != NULL)
         {
                 mBufferName = new char[strlen(label)+1];
                 strcpy(mBufferName,label);
         }
 }
 
 template <class T, class F>
 Buffer<T,F>::Buffer(const Buffer<T,F>& b) :
                 mBufferLength(0), mOverflowReported(FALSE),
                 mBuffer(NULL), mInBuffer(0), mBufferName(NULL)
 {
 }
 
 template <class T, class F>
 Buffer<T,F>::~Buffer()
 {
         if (mBuffer != NULL)
         {
                 delete [] mBuffer;
                 mBuffer = NULL;
                 mBufferLength = 0;
                 reset();
         }
         if (mBufferName != NULL)
         {
                 delete [] mBufferName;
                 mBufferName = NULL;
         }
 }
 
 template <class T, class F>
 T*
 Buffer<T,F>::buf() const
 {
         return mBuffer;
 }
 
 template <class T, class F>
 int
 Buffer<T,F>::bufLength() const
 {
         return mInBuffer;
 }
 
 template <class T, class F>
 bool
 Buffer<T,F>::canAddTo()
 {
         if ( mInBuffer == mBufferLength )
         {
                 if (!mOverflowReported)
                 {
                         mOverflowReported = TRUE;
                         if (mBufferName != NULL)
                                 cerr << mBufferName << ": ";
                         cerr << "Buffer overflow\n";
                 }
                 return FALSE;
         }
         return TRUE;
 }
 
 template <class T, class F>
 void
 Buffer<T,F>:: reset()
 {
         mOverflowReported = FALSE;
         mInBuffer = 0;
 }
 
 //////////////// Subclass for buffering arrays /////////////////////////////
 
 template <class T, class F>
 class BufferV : public Buffer<T,F>
 {
 public:
         BufferV(int length=100, char* label=NULL);
         virtual ~BufferV();
 
         virtual bool    add(F item);
 
 private:
         BufferV(const BufferV<T,F>& b);
 };
 
 template <class T, class F>
 BufferV<T,F>::BufferV(int length, char* label) : Buffer<T,F>(length,label)
 {
 }
 
 template <class T, class F>
 BufferV<T,F>::BufferV(const BufferV<T,F>& b) : Buffer<T,F>(b)
 {
 }
 
 template <class T, class F>
 BufferV<T,F>::~BufferV()
 {
 }
 
 template <class T, class F>
 bool
 BufferV<T,F>::add(F item)
 {
 
         cout    << "item = " << item[0] << ", " 
                 << item[1] << ", " << item[2] <<  endl;
 /*
         For some reason the following line yields the correct output
         when instantiated with F = int[3] or F = float[3]               
         cout    << "item = " << item[0+3] << ", " 
                 << item[1+3] << ", " << item[2+3] <<  endl;
 */
 
         if (Buffer<T,F>::canAddTo())
         {
                 cout << "mBuffer[" << mInBuffer << "] = ";
                 for (int i=0 ; i<3 ; i++) {
 /* 
         See above when instanciated with F = int[3] and float[3]        
                         mBuffer[mInBuffer][i] = item[i+3];
 */
                         mBuffer[mInBuffer][i] = item[i];
                         cout << mBuffer[mInBuffer][i] << ", ";
                 }
                 cout << endl;
                 mInBuffer++;
                 return TRUE;
         }
         return FALSE;
 }
 
 
 
 //typedef int  Dxyz[3],  *DxyzP;
 //typedef float  Dxyz[3],  *DxyzP;
 typedef double  Dxyz[3],  *DxyzP;
 
 static BufferV<Dxyz,Dxyz>       faceVertexBuf(10,"faceVertexBuf");
 
 Dxyz    input_points[4]={       {1.0, -1.0, 1.0},{1.0, 1.0, -1.0},
                                 {1.0, 1.0, 1.0},{1.0, -1.0, 1.0} };
 
 int main (int argc, char* argv[])
 {
         int i = 0, index;
         faceVertexBuf.reset();
 
         for (i=0;i<4; i++) {
 
                 index = faceVertexBuf.bufLength();
                 Dxyz    temp = {input_points[i][0], 
                                 input_points[i][1], 
                                 input_points[i][2]};
 
                 cout << "Input = " << temp[0] << ", " 
                      << temp[1] << ", " <<  temp[2] << endl; ;
 
                 faceVertexBuf.add(temp);
                 DxyzP tempP = faceVertexBuf.buf()[index];
 
                 cout << "Output = " << tempP[0] << ", " 
                      << tempP[1] << ", " <<  tempP[2] << endl; ;
 
         }
 
         return 0;
 }


             reply	other threads:[~2001-05-29 10:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-29 10:56 Ian Williams [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-08-20 14:16 c++/2892 Craig Rodrigues
2001-08-10  9:46 c++/2892 Joe Goyette
2001-05-28  3:16 c++/2892 nathan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010529175601.3983.qmail@sourceware.cygnus.com \
    --to=ianw@sgi.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).