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.
12409 Discussions

Does the alt_u16 type support 0xFFFF or not?

Altera_Forum
Honored Contributor II
931 Views

Please consider the following code: 

 

... alt_u16 i; .... for(i=0x0000; i<=0xFFFF; i++) ...  

 

I am getting the following warning during my compilation: 

 

comparison is always true due to limited range of data type 

 

To temporarily solve this I changed the upper limit from 0xFFFF to 0xFFFE 

 

My questions are: 

  1. Why this is happening? I ask this because I was thinking that the alt_u16 as an unsigned 16 bit could fit the 0xFFFF 

  2. Do I need to increase the type alt_u16 to alt_u32 only to support one additional bit or how can I solve this problem? 

0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
172 Views

alt_u16 can hold 0xFFFF, but it can't hold anything larger than that. So the comparison "<= 0xFFFF" is always true. Which is exactly what the compiler is telling you the problem with your code is. 

 

You can use an alt_u32 to keep the rest of your for() loop the same as already written.
Altera_Forum
Honored Contributor II
173 Views

 

--- Quote Start ---  

alt_u16 can hold 0xFFFF, but it can't hold anything larger than that. So the comparison "<= 0xFFFF" is always true. Which is exactly what the compiler is telling you the problem with your code is. 

 

You can use an alt_u32 to keep the rest of your for() loop the same as already written. 

--- Quote End ---  

 

 

thanks again, ted
Reply