Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:43:15+00:00 2026-06-01T14:43:15+00:00

Ive got a multi platform project that compiles great on mac, but on windows

  • 0

Ive got a multi platform project that compiles great on mac, but on windows all my swprintf calls with a %s are looking for a wchar_t instead of the char * im passing it. Turns out M$ thought it would be funny to make %s stand for something other than char * in wide character functions… http://msdn.microsoft.com/en-us/library/hf4y5e3w.aspx

Anyways I’m looking for a creative coding trick thats better than putting ifdef else ends around every wide string call

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:43:17+00:00Added an answer on June 1, 2026 at 2:43 pm

    Update: VS 2015 CTP6 reverted the changes and Microsoft are yet again acting different to the standard.


    Visual Studio 14 CTP1 and later will always treat %s as a narrow string (char*) unless you define _CRT_STDIO_LEGACY_WIDE_SPECIFIERS. It also added the T length modifier extension which maps to what MS calls the “natural” width. For sprintf %Ts is char* and for swprintf %Ts is wchar_t*.


    In Visual Studio 13 and earlier %s/%c is mapped to the natural width of the function/format string and %S/%C is mapped to the opposite of the natural with:

    printf("%c %C %s %S\n", 'a', L'B', "cd", L"EF");
    wprintf(L"%c %C %s %S\n", L'a', 'B', L"cd", "EF");
    

    You can also force a specific width by using a length modifier: %ls, %lc, %ws and %wc always mean wchar_t and %hs and %hc are always char. (Documented for VS2003 here and VC6 here (Not sure about %ws and when it was really added))

    Mapping %s to the natural width of the function was really handy back in the days of Win9x vs. WinNT, by using the tchar.h header you could build narrow and wide releases from the same source. When _UNICODE is defined the functions in tchar.h map to the wide functions and TCHAR is wchar_t, otherwise the narrow functions are used and TCHAR is char:

    _tprintf(_T("%c %s\n"), _T('a'), _T("Bcd"));
    

    There is a similar convention used by the Windows SDK header files and the few format functions that exist there (wsprintf, wvsprintf, wnsprintf and wvnsprintf) but they are controlled by UNICODE and TEXT and not _UNICODE and _T/_TEXT.

    You probably have 3 choices to make a multi-platform project work on Windows if you want to support older Windows compilers:

    1) Compile as a narrow string project on Windows, probably not a good idea and in your case swprintf will still treat %s as wchar_t*.

    2) Use custom defines similar to how inttypes.h format strings work:

    #ifdef _WIN32
    #define PRIs "s"
    #define WPRIs L"hs"
    #else
    #define PRIs "s"
    #define WPRIs L"s" 
    #endif
    printf("%" PRIs " World\n", "Hello");
    wprintf(L"%" WPRIs L" World\n", "Hello");
    

    3) Create your own custom version of swprintf and use it with Visual Studio 13 and earlier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some multi threaded code that typically runs great, but every so often
I've got a big multi-module project, and I'd like to generate a report that
I've got a c# WINDOWS Application that is multi-threaded. It is my understanding that
As the Title says, I've got a multi-project solution. I've got a core project
ive got an object that looks like this with print_r(): SimpleDOM Object ( [0]
What are the possible ways to solve a maze? Ive got two ideas, but
I'm looking to draw a cube at specific co-ordinates. I've got all 4 corners
I've got an app that lets users send sms messages. Works great when the
I've got a XAML Browser Hosted Application (XBAP) project that has a dependency on
I've recently started using CMake for one of my multi-platform projects, but I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.