Pelles C forum

Pelles C => Bug reports => Topic started by: JohnF on November 04, 2005, 10:22:48 AM

Title: printf & wprintf - crt.lib
Post by: JohnF on November 04, 2005, 10:22:48 AM
With msvcrt.lib one can use printf and wprintf but with crt.lib one can only use one of them, the same goes for fprintf and fwprintf.

The one that is used depends on which one comes first in the listing.


#include <stdio.h>
#include <wchar.h>

int main(void)
{
char str[] = "Qwerty";
wchar_t wstr[] = L"Qwerty";

printf("char %s\n", str);
wprintf(L"wchar %ls\n", wstr);

return 0;
}


John
Title: printf & wprintf - crt.lib
Post by: Pelle on November 04, 2005, 08:13:09 PM
This is correct behaviour, as I understand it. Streams can in C99 be either byte-oriented or wide-oriented (they start with no orientation). Using a mix of orientation is undefined. When you use a byte-oriented function, like printf, the stream is set to byte-oriented. The function fwide can be used to set/check the orientation (can't change it, once it's set).

Pelle
Title: printf & wprintf - crt.lib
Post by: JohnF on November 04, 2005, 10:00:02 PM
Quote from: "Pelle"This is correct behaviour, as I understand it. Streams can in C99 be either byte-oriented or wide-oriented (they start with no orientation). Using a mix of orientation is undefined. When you use a byte-oriented function, like printf, the stream is set to byte-oriented. The function fwide can be used to set/check the orientation (can't change it, once it's set).

Pelle

Ok thanks, you are right.

Is this restriction new to C99 do you know?

John
Title: printf & wprintf - crt.lib
Post by: Pelle on November 05, 2005, 03:49:52 PM
Not sure. I don't have all the standard C documents available. The function fwide() was added in C99, and the whole issue became more "visible" at least...

Pelle
Title: printf & wprintf - crt.lib
Post by: JohnF on November 05, 2005, 04:52:24 PM
Quote from: "Pelle"Not sure. I don't have all the standard C documents available. The function fwide() was added in C99, and the whole issue became more "visible" at least...

Pelle

Ok thanks.

John