NO

Author Topic: Problem mixing printf() and wprintf() in same app  (Read 5395 times)

Ron Pinkas

  • Guest
Problem mixing printf() and wprintf() in same app
« on: December 25, 2005, 04:55:34 AM »
Hi Pelle,

I'm not able to get both the ansi and wide version of printf to work correctly in the same app. The following reduced sample, performs as expected with MSVC (6, 7, 8) and BCC 5.5.1, but produces unexpected results with Pelles C 4.00.50 (on Win XP Pro SP-2):

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

int main( int argc, char *argv[] )
{
    printf( "Hello, world 1!\n" );
    wprintf( L"Hello, world 2!\n" );
    return 0;
}
//--------------------------------------------//

1. Is there anyway to allow mixed usage of ansi and wide version in same exe?

2. How may I obtain the sources of the latest Pelles C?

Thanks in advance,

Ron

Offline Robert

  • Member
  • *
  • Posts: 247
Re: Problem mixing printf() and wprintf() in same app
« Reply #1 on: December 25, 2005, 05:26:22 AM »
Quote from: "Ron Pinkas"
Hi Pelle,

I'm not able to get both the ansi and wide version of printf to work correctly in the same app. The following reduced sample, performs as expected with MSVC (6, 7, 8) and BCC 5.5.1, but produces unexpected results with Pelles C 4.00.50 (on Win XP Pro SP-2):

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

int main( int argc, char *argv[] )
{
    printf( "Hello, world 1!\n" );
    wprintf( L"Hello, world 2!\n" );
    return 0;
}
//--------------------------------------------//

1. Is there anyway to allow mixed usage of ansi and wide version in same exe?

2. How may I obtain the sources of the latest Pelles C?

Thanks in advance,

Ron


For answer to question 1 see thread at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=878&highlight=wprintf

For answer to question 2 see FAQ at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=34&highlight=source

Robert Wishlaw

Ron Pinkas

  • Guest
Problem mixing printf() and wprintf() in same app
« Reply #2 on: December 25, 2005, 06:19:10 AM »
Robert, Pelle,

"For answer to question 1 see thread at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=878&highlight=wprintf"

Robert, thanks for the prompt reply.

FWIW, the limitation implied by the response in the above thread seems odd. There may be valid reasons for an application to have a mix usage of both ansi and wide strings, f.e. considering that OLE API requires wide strings. Additionally, an application may be linked to multiple Libs, which may use either version. Finally, none of the other compilers I tested seems to exhibit this limitation.

I'm qurious if aside of the possible undefined behaviour implied by C99, is there any technical problem, or serious difficulty, in allowing both versions to co-exists?

"For answer to question 2 see FAQ at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=34&highlight=source"

Pelle, I'm not able to contact you by private email, could you please forward pricing info, to ron at xharbour.com?

Thanks in advance,

Ron

Offline Robert

  • Member
  • *
  • Posts: 247
Problem mixing printf() and wprintf() in same app
« Reply #3 on: December 25, 2005, 10:45:39 AM »
Quote from: "Ron Pinkas"
Robert, Pelle,

"For answer to question 1 see thread at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=878&highlight=wprintf"

Robert, thanks for the prompt reply.

FWIW, the limitation implied by the response in the above thread seems odd. There may be valid reasons for an application to have a mix usage of both ansi and wide strings, f.e. considering that OLE API requires wide strings. Additionally, an application may be linked to multiple Libs, which may use either version. Finally, none of the other compilers I tested seems to exhibit this limitation.

I'm qurious if aside of the possible undefined behaviour implied by C99, is there any technical problem, or serious difficulty, in allowing both versions to co-exists?

"For answer to question 2 see FAQ at

http://smorgasbordet.com/phpBB2/viewtopic.php?t=34&highlight=source"

Pelle, I'm not able to contact you by private email, could you please forward pricing info, to ron at xharbour.com?

Thanks in advance,

Ron


Undefined behaviour is serious difficulty. See the thread "Dangerous glibc byte/wide stream interactions" at

http://sources.redhat.com/ml/libc-alpha/2000-09/msg00335.html

For the Microsoft perspective of the valid states, and state transitions, for a stream see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/LIB_FILE_Stream_States.asp

Robert Wishlaw