cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

RaAl_264636
Contributor II

Hi,

I'm using printf with a variable of type uint32_t. Variables of this type have a fixed with of 32 bits, so this equals to long int in C. Is this true?

So, for printf, the correct format string is:

printf("%lu", Var);     //%lu => long unsigned

Now, it's getting strange: If I use %lu, I get no error in the notice list after a build, but a error indicator in the corresponding line of the source editor window, saying "format specifies type 'unsigned long', but the argument has type 'uint32_t' (aka 'unsigned int')".

If I use %u, the error indicator in the source editor window wents away, but after a build a warning is shown in the notice list: "format '%u' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t {aka long unsigned int}"

This is confusing. I know I can use

printf("%lu", (long int)Var);

which eliminates both error indicators, but I wonder why there are errors different positions (source code window vs. notice list), and why %lu gives an error - %lu should be right IMHO.


Is the behaviour regarding the error messages a bug of PSoC Creator? Should I file a case about it?

Regards,

Ralf

0 Likes
Reply
1 Solution
SrikanthD_56
Employee

Try using uint32 instead of uint32_t, you should not see any warnings.C_var.png

View solution in original post

0 Likes
Reply
7 Replies
AnkitaS_51
Employee

I tried what you mentioned by writing this code in main.c-

uint32_t var=0x00023;

    CyGlobalIntEnable; /* Enable global interrupts. */

printf("%lu",var );

But I didn't got any error indicator ( screenshot attached ) in PSoC Creator4.1 update1.

Can you please provide the project in which you are observing the issue.

0 Likes
Reply
RaAl_264636
Contributor II

Hi Anks,

you missed to include <stdio.h>. Please try it with including this file. I attached screenshots of the behaviour, one with %u and one with %lu, pictures are taken after rebuild.

Regards,

Ralf

0 Likes
Reply
SrikanthD_56
Employee

Try using uint32 instead of uint32_t, you should not see any warnings.C_var.png

View solution in original post

0 Likes
Reply
RaAl_264636
Contributor II

Hi srds,

thank you, I'll try it. So, this issue is because the IDE is not capable of determining the bit width of uint32_t for the printf arguments?

Regards

0 Likes
Reply
SrikanthD_56
Employee

Note that it is a diagnostic warning in the code editor (since the typedef are different) and not a compiler generated warning. So, both uint32 and uint32_t functionally work the same way.

0 Likes
Reply
TareeshK_21
Employee

even with uint32 i am getting warning in editor to change to %u from %lu, but if i do that then compiler gives warning.

0 Likes
Reply
SrikanthD_56
Employee

If you are using PSoC 6 MCU, try this:

printf("Value of Val: %lu\r\n", (unsigned long)Val);