- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
PSoC Creator Software
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try using uint32 instead of uint32_t, you should not see any warnings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try using uint32 instead of uint32_t, you should not see any warnings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
even with uint32 i am getting warning in editor to change to %u from %lu, but if i do that then compiler gives warning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are using PSoC 6 MCU, try this:
printf("Value of Val: %lu\r\n", (unsigned long)Val);