This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi there,
I'm working with a customer who is using CCS 3.3 and the TMS320C6713 target board. We have come across a strange issue to do with printing numbers. Here is the code snippet we are using:
#include <stdio.h>
void takesUnsignedLong(unsigned long m) {
printf("\n%08lX", (unsigned long) m );
}
void takesLong(long l) {
printf("\n%08lX", l );
takesUnsignedLong((unsigned long) l);
}
int main(void) {
printf("Negative: \n%08lX", -1166898241 );
takesLong(-1166898241);
printf("\n\nPositive: \n%08lX", 3128069055 );
takesLong(3128069055);
return 0;
}
I would expect this snippet to return the following output:
Negative:
BA728BBF
BA728BBF
BA728BBF
Positive:
BA728BBF
BA728BBF
BA728BBF
However in the customer's environment the output is as follows:
Negative:
BA728BBF
FFBA728BBF
FFBA728BBF
Positive:
BA728BBF
BA728BBF
BA728BBF
This output is strange because (a) printf should not be able to print 10 characters when asked for 8 and (b) the same value should be printed each time.
Could you please let me know whether this is a bug in the CCS compiler? And if so, is it fixed in a later version?
Thanks,
Emma
I assume your customer is using COFF mode. In COFF, the type "long" is 40 bits, and is thus 10 hex characters. The field width specifier in the printf format string is a minimum field width, not a maximum. Therefore, this is the output I would expect. If the customer requires 32-bit "long" type, use EABI mode. New projects should use EABI mode if possible.