We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, colleagues!
My question is about work with function sprintf in Keil C for ARM.
I have a structure for RTC, that looking as:
struct { unsigned char SEC; unsigned char MIN; unsigned char HOUR; unsigned char DWEEK; unsigned char DAY; unsigned char MONTH; int YEAR; } RTC8583;
I try to write function that showing time:
sprintf (BUFF,"%02d:%02d:%02d", (unsigned)RTC8583.HOUR,(unsigned)RTC8583.MIN,(unsigned)RTC8583.SEC);
And after compilation, a message is displayed all the time:
... compiling M1132_MAIN.c... MAIN\M1132_MAIN.c(284): warning: #167-D: argument of type "BYTE *" is incompatible with parameter of type "char *restrict" sprintf (BUFF,"%02d:%02d:%02d", (unsigned)RTC8583.HOUR,(unsigned)RTC8583.MIN,(unsigned)RTC8583.SEC); MAIN\M1132_MAIN.c: 1 warning, 0 errors ...
I can’t understand how to do it right so that there is no warning!
It is still strange that neither in Borland C++, nor in Keil C for C51 such a is observed!
Help me please!
Hi Oleg,
I can't replicate this with trivial examples, how is BUFF defined? Signed or unsigned char* ? I get different errors (rather than warnings) if I use unsigned chars, but the below builds fine for me with both armcc and armclang.
#include <stdio.h> extern char BUFF1[10]; extern char BUFF2[]; extern char* BUFF3; struct { unsigned char SEC; unsigned char MIN; unsigned char HOUR; unsigned char DWEEK; unsigned char DAY; unsigned char MONTH; int YEAR; } RTC8583; void foo(){ sprintf (BUFF1,"%02d:%02d:%02d",(unsigned)RTC8583.HOUR,(unsigned)RTC8583.MIN,(unsigned)RTC8583.SEC); sprintf (BUFF2,"%02d:%02d:%02d",(unsigned)RTC8583.HOUR,(unsigned)RTC8583.MIN,(unsigned)RTC8583.SEC); sprintf (BUFF3,"%02d:%02d:%02d",(unsigned)RTC8583.HOUR,(unsigned)RTC8583.MIN,(unsigned)RTC8583.SEC); return; }
Hello, Ronan!
Until yesterday, I always used the BUFF1 option inside and outside the function, as well as the BUFF3 option inside the function...
And I received a warning, although the code executed correctly for the BUFF1.
Yesterday I defined BUFF3 outside the function - the warning disappeared... Although this is generally strange, because the definition of the BUFF1 is correct in most cases ...
Regards,
Oleg Nicolaiciuc