Another take on decimal data types

kdevel kdevel at vogtner.de
Thu Jan 11 21:12:59 UTC 2018


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.

Sure.
http://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html

> What did you expect?

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

mis.c
```
#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);





More information about the Digitalmars-d-announce mailing list