How do I customize output of a custom type using printf?

It looks like the Right Way to do this in F# 2.0 is by using the StructuredFormatDisplay attribute, for example: [<StructuredFormatDisplay(“hello {a}”)>] type myType = {a: int} In this example, instead of the default {a = 42;}, you would get hello 42. This works the same way for object, record, and union types. And although … Read more

Why does printf() promote a float to a double?

Yes, float arguments to variadic function are promoted to double. The draft C99 standard section 6.5.2.2 Function calls says: […]and arguments that have type float are promoted to double. These are called the default argument promotions.[…] from the draft C++ standard section 5.2.2 Function call: […]a floating point type that is subject to the floating … Read more

Passing too many arguments to printf

Online C Draft Standard (n1256), section 7.19.6.1, paragraph 2: The fprintf function writes output to the stream pointed to by stream, under control of the string pointed to by format that specifies how subsequent arguments are converted for output. If there are insufficient arguments for the format, the behavior is undefined. If the format is … Read more

printf not printing on console

Output is buffered. stdout is line-buffered by default, which means that ‘\n’ is supposed to flush the buffer. Why is it not happening in your case? I don’t know. I need more info about your application/environment. However, you can control buffering with setvbuf(): setvbuf(stdout, NULL, _IOLBF, 0); This will force stdout to be line-buffered. setvbuf(stdout, … Read more