On Thursday, 11 January 2018 at 21:12:59 UTC, kdevel wrote:
On Thursday, 11 January 2018 at 20:40:01 UTC, Dmitry Olshansky wrote:
   printf ("%.2f\n", d);

C’s printf by definition can’t be customized.


“”” GNU C Library lets you define “””

Here is your compatibility story.

What did you expect?

To be honest: A compile time error. Modern C compilers can check such format strings. Example: GCC 6:

1. It’s a warning.
2. There is no typechecking it’s just a hardcoded linting in the compiler. 3. It’s D use writefln or if going for C primitives know their quirks. 4. Passing anything but basic types to C vararg is undefined in C++ IIRC, dunno what D should do about it.

#include <stdio.h>

int main ()
   double d = 0;
   printf ("%p\n", d);
   return 0;

$ gcc -Wall mis.c
mis.c: In function 'main':
mis.c:6:14: warning: format '%p' expects argument of type 'void *', but argument 2 has type 'double' [-Wformat=]
    printf ("%p\n", d);

Reply via email to