NO

Author Topic: printf & wprintf - crt.lib  (Read 5531 times)

JohnF

  • Guest
printf & wprintf - crt.lib
« 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.

Code: [Select]

#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

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
printf & wprintf - crt.lib
« Reply #1 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
/Pelle

JohnF

  • Guest
printf & wprintf - crt.lib
« Reply #2 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

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
printf & wprintf - crt.lib
« Reply #3 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
/Pelle

JohnF

  • Guest
printf & wprintf - crt.lib
« Reply #4 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