Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

C++ Templates

Hello experts

BUG in NIOS2 C++ compiler

Declaration below, is template Class which valid (we where check it at other compilers )

///////// IT IS VALID CODE BUT COMPILER TROW ERROR!!!!

//////// look to the end of string which begin with FlatScreen ....

template <class T> class FlatScreen:public Screen

{

protected:

int32 line_width;

T* mData;

virtual void close(void);

//---------------------------------------------------------------------------------------------LOOK HERE

FlatScreen(int w,int h,int bpp,size_t lw,T* ptr):Screen(w,h,bpp),mData(ptr),line_width(lw?lw:w*sizeof(T)) //line_width(lw?lw:w*sizeof(T) - MUST BE ASSIGNED

{

assert(mData);

}

public:

T* GetPtr(void) { return mData; }

virtual ~FlatScreen(void);

virtual void _PutPixel(int x,int y,uint32 color);

virtual uint32 _GetPixel(int x,int y);

virtual void _vline(int x,int y,int h,uint32 color);

virtual void _line(int x0,int y0,int x1,int y1,uint32 color);

virtual void _outchar(int x,int y,uint ch,uint32 color,const cRect* rect);

virtual void _PutImage(int x,int y,const tPicture* image,const cRect* rect);

virtual void _GetImage(int x,int y,int w,int h,tPicture* image,const cRect* rect);

virtual void _BitBlt(int x,int y,int w,int h,const void* image,const cRect* rect);

};

To solve that problem we replace assigning of values to constuctor body

like shown below :

template <class T> class FlatScreen:public Screen

{

protected:

int32 line_width;

T* mData;

virtual void close(void);

//----------------------- !!!!!!!!!!!!!!!!!!!!!!!!!!!!

FlatScreen(int w,int h,int bpp,size_t lw,T* ptr):Screen(w,h,bpp),mData(ptr)

{

assert(mData);

line_width=lw?lw:w*sizeof(T); // Replased from constructor because nios2-elf-gcc compiler have a BUG!!!

}

public:

T* GetPtr(void) { return mData; }

virtual ~FlatScreen(void);

virtual void _PutPixel(int x,int y,uint32 color);

virtual uint32 _GetPixel(int x,int y);

virtual void _vline(int x,int y,int h,uint32 color);

virtual void _line(int x0,int y0,int x1,int y1,uint32 color);

virtual void _outchar(int x,int y,uint ch,uint32 color,const cRect* rect);

virtual void _PutImage(int x,int y,const tPicture* image,const cRect* rect);

virtual void _GetImage(int x,int y,int w,int h,tPicture* image,const cRect* rect);

virtual void _BitBlt(int x,int y,int w,int h,const void* image,const cRect* rect);

};

I&#39;ts fundamental BUG - and i guess it not last bug of C++ compiler .... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif

So is it possible to fix BUG&#39;s of that type in NEXT release ?

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Can you please post both the error message you are getting from the compiler, and if possible a reduced test case?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I guess the reason you want the initializer version of your code to work is so you can declare line_width as const int32 instead of just int32.

    Do either of the following work?

    FlatScreen(int w,int h,int bpp,size_t lw,T* ptr):Screen(w,h,bpp),mData(ptr),line_width(lw?lw:size_t(w)*sizeof(T))

    FlatScreen(int w,int h,int bpp,size_t lw,T* ptr):Screen(w,h,bpp),mData(ptr),line_width(size_t(lw?lw:w*sizeof(T)))

    And yes, please show us the actual error message.