Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,092 Views

alt_types.h printf warning

Hi, 

 

I am writing some C for a NIOS. I am using the data formats defined in alt_types.h, alt_u32 alt_u16 alt_u8.  

 

When I use printf with alt_u32 I am getting a warning: 

 

warning: format '%x' expects argument of type 'unsigned int', but argument <number> has type 'alt_u32' 

 

The printf still works and returns what I am expecting through the stdout.  

 

code example: 

 

void main(void) { alt_u8 test1; test1 = 0x04; printf("test1: %02x\n",test1); alt_u32 test2; test2 = 0x01020304; printf("test2: %08x\n",test2); return; }  

 

when compiled gives the above warning for both printf statements (note both errors state argument has type alt_u32 even though one is alt_u8) 

 

When I run this on my board the output is: 

 

test1: 04 

test2: 01020304 

 

My questions are: 

 

1) Can I ignore this warning? I am assuming I can as it still works functionally 

 

2) Can I get rid of it as I dont want every printf I use giving a warning when compiling.  

 

3) Should I be using alt_types and alt_uX at all? should I use a more standard format? I am using them as they are in the software handbook and it seemed like the right idea.  

 

Thanks 

 

James
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
123 Views

1) Odds are, you can probably just ignore the warning if it's still giving you the correct output (even though the types differ, C will perform an implicit type conversion to convert it into an unsigned integer). 

 

2) If you would like to get rid of the warning, you can always explicitly type cast the variable into a unsigned integer, like so: 

printf("test2: %08x\n", (unsigned int)test2); 

 

3) If you're going to be passing data into Altera functions (either drivers or the HAL), it's probably best to keep using the alt_* types, although if you don't mind occasionally doing an explicit conversion, you can use the usual types.
Altera_Forum
Honored Contributor I
123 Views

Consider to kill those warnings..... 

 

1) right click on your project file, go to property 

2) then go to C/C++ General tab, go to code analysis. 

3) change the bullet to "use project setting" , and start disable those warning that you do not wish to see(of course only if this is not a serious error)
Altera_Forum
Honored Contributor I
123 Views

Hi, thanks for replying! wasnt sure if this post would get lost or not, didnt want to post such a specific question on the general one.  

 

Casting using (unsigned int) worked!  

 

Although I had been ignoring the errors as the output was coming back as I expected I definately prefer fixing them wiht the cast compared to covering them up. 

 

James