How do I printf() a uint16_t?

You should use the style of inttypes.h but define the symbols yourself. For example: #define PRIu8 “hhu” #define PRId8 “hhd” #define PRIx8 “hhx” #define PRIu16 “hu” #define PRId16 “hd” #define PRIx16 “hx” #define PRIu32 “u” #define PRId32 “d” #define PRIx32 “x” #define PRIu64 “llu” // or possibly “lu” #define PRId64 “lld” // or possibly “ld” … Read more

Correct printf format specifier for size_t: %zu or %Iu?

MS Visual Studio didn’t support %zu printf specifier before VS2013. Starting from VS2013 (e.g. _MSC_VER >= 1800) %zu is available. As an alternative, for previous versions of Visual Studio if you are printing small values (like number of elements from std containers) you can simply cast to an int and use %d: printf(“count: %d\n”, (int)str.size()); … Read more

What’s the meaning of the %m formatting specifier?

m conversion specifier is not C but is a GNU extension to printf: From GNU documentation: http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html The ‘%m’ conversion prints the string corresponding to the error code in errno. See Error Messages. Thus: fprintf (stderr, “can’t open `%s’: %m\n”, filename); is equivalent to: fprintf (stderr, “can’t open `%s’: %s\n”, filename, strerror (errno)); The ‘%m’ … Read more

What is the purpose of the h and hh modifiers for printf?

One possible reason: for symmetry with the use of those modifiers in the formatted input functions? I know it wouldn’t be strictly necessary, but maybe there was value seen for that? Although they don’t mention the importance of symmetry for the “h” and “hh” modifiers in the C99 Rationale document, the committee does mention it … Read more

Platform independent size_t Format specifiers in c?

Yes: use the z length modifier: size_t size = sizeof(char); printf(“the size is %zu\n”, size); // decimal size_t (“u” for unsigned) printf(“the size is %zx\n”, size); // hex size_t The other length modifiers that are available are hh (for char), h (for short), l (for long), ll (for long long), j (for intmax_t), t (for … Read more

Why is printf with a single argument (without conversion specifiers) deprecated?

printf(“Hello World!”); is IMHO not vulnerable but consider this: const char *str; … printf(str); If str happens to point to a string containing %s format specifiers, your program will exhibit undefined behaviour (mostly a crash), whereas puts(str) will just display the string as is. Example: printf(“%s”); //undefined behaviour (mostly crash) puts(“%s”); // displays “%s\n”

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)