Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Can't mix printf with wprintf?

    int main (int argc, char *argv[])
    Output of this program is
    I am using gcc 4.0.2 on SUSE 10.0.

    The GNU C Library Section 12.6 Streams in Internationalized Applications, it clearly states that you can not mix these two. Or am I missing something?
    It is important to never mix the use of wide and not wide operations on a stream. There are no diagnostics issued. The application behavior will simply be strange or the application will simply crash.
    Now I can understand this might be an issue for other streams but now we are talking about console output.

    I have several questions.
    . Am I missing something?
    . Is this a known issue? I never heard something like this before, and google returns nothing useful.
    . Is there a workaround? A compiler switch, a environmental variable to mess with, something?
    How do people solve this issue when using several different libraries and each using a diffrent (w)printf and/or (w)cout?


  2. #2
    I suggest this workaround:

    int main() {
        wprintf(L"%s", "printf1\n");
        wprintf(L"%ls", L"wprintf\n");
        wprintf(L"%s", "printf2\n");
    This does the right thing on my system (glibc 2.3.5-r2 and gcc 3.3.5):
    Or am I missing something, now?

  3. #3
    If you always use wprintf then yes. It works. But the problem is you can not always control that.

    The most simple case I can think of is ...
    Lets say I am using a third party library, that has nothing to do with wprintf, and this library is using printf (or cout, whatever) for their ... say debug output.

    Now my application, I have to use wprintf, there is no way around it. Now either my output or theirs are blocked. I have to convert the stream (in this case the console) using fwide (or whatever) everytime I call a function in that third party library, whether it is output releated or not, because they might use printf.

  4. $spacer_open
  5. #4
    I don't see any obvious solution to the problem, in that case -- other than calling fwide every time you use the third-party library, of course. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts