Skip to content

Generic printf function does not implement microsoft specifiers  #1433

@kbsec

Description

@kbsec

*Describe the bug
The implementation of printf/wprintf has incorrect behavior when used for windows.
see documentation here:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-170

If I have time in the next few weeks, I'll submit a pr :)
Sample Code

#include <windows.h>
#include <stdio.h> 

# define W 

int main(){
  // https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-170
  // The windows implementation of printf/wprintf 
  // type field characters does not confirm to ISO C stanards 
  // In particular, the behavior of %s/%S is differnt depending on 
  // on wether printf/wprintf is called 
  #ifdef W
  wprintf(L"I am a C string %s\n", "hello world!");
  wprintf(L"I amd a Wide C string %s\n", L"hello world!");
  #else 
  printf("I am a C string %s\n", "hello world!");
  printf("I amd a Wide C string %S\n", L"hello world!");
  #endif 

}
 x86_64-w64-mingw32-gcc windows_printf.c -DW -o wprintf.exe
 x86_64-w64-mingw32-gcc windows_printf.c  -o printf.exe

Expected behavior
wine64 wprintf.exe
I am a C string hello world!
I amd a Wide C string h

wine64 printf.exe
I am a C string hello world!
I amd a Wide C string hello world!

Screenshots
image

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingos winWindows emulation related

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions