![]() ).This is a comparison of currently (early 2018) available C implementations targeting the STM8. The C Standard ( 6.5.2.2 Function calls) explicitly defines this call as having undefined behavior if the function is defined (in the library) with a prototype that includes an ellipsis (. It seems printf() passes uint8_t values incorrectly, in a non conforming way.Īnother potential source of problems is if you forgot to include and are calling printf without a definition with a prototype. Observing that printf("%x\n\r", test_payload test_payload) seems to work fine, the problem is not passing an int instead of an unsigned int, which would have been bad enough. Definitely try casting the arguments as in printf("%x\r\n", (unsigned int)test_payload) You could try changing the format to %hhx or casting the argument as (unsigned int)test_payload, but it would be very surprising that one of these changes alone fix the problem.ĮDIT: from your extra information, it looks like the compiler for your embedded target is very peculiar. Technically, printf expects an unsigned int argument for a %x conversion format, but an int value should work fine and test_payload is promoted to int and passed as such to printf. Post a complete program that exhibits the offending behavior, or change the format as %x\n to separate 58 from subsequent output. It is possible that you output 86 in the code that follows the fragment. The first code fragment should produce 58, but you do not output a newline, so any subsequent output will appear right after the 58. Printf("%x\n\r", test_payload test_payload) This is the test code test_payload = (uint8_t)0x58 I trimmed it all down to the following example: But for some reason I am getting weird values when I print a uint8_t - I get the expected value plus some other value (it is always the same extra value), as if I was printing a uint16_t or other 16bit value. I'm manipulating values in an uint8_t array and printing it out to my terminal to verify if everything is correct. Printf gives me weird extra values in some cases. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |