Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

C++ Templates

Altera_Forum
Honored Contributor I
789 Views

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 ?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor I
54 Views

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

Altera_Forum
Honored Contributor I
54 Views

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