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

  • SEARCH
  • Home
  • 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 6769409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:11:25+00:00 2026-05-26T15:11:25+00:00

The C++11 standard specifies that vwscanf is available via header <cwchar> (and therefore <wchar.h>

  • 0

The C++11 standard specifies that vwscanf is available via header <cwchar> (and therefore <wchar.h>). However it seems to be lacking in Visual C++. With that function I could write …

inline int scanf( CodingValue const* format, ... )
{
    va_list args;
    va_start( args, format );
    return ::vwscanf( format->ptr(), args );
}

but without it, i.e. with Visual C++ 10.0, which also appears to lack support for C++11 variadic templates, I’m reduced to writing …

inline int scanf(
    CodingValue const* format,
    void* a01 = 0, void* a02 = 0, void* a03 = 0, void* a04 = 0, void* a05 = 0,
    void* a06 = 0, void* a07 = 0, void* a08 = 0, void* a09 = 0, void* a10 = 0,
    void* a11 = 0, void* a12 = 0
    )
{
    int const   nArgs = !!a01 + !!a02 + !!a03 + !!a04 + !!a05 + !!a06 +
                        !!a07 + !!a08 + !!a09 + !!a10 + !!a11 + !!a12;
    BasicCodingValue const* const   f   = format->ptr();

    switch( nArgs )
    {
    case  0:    return ::wscanf( f );
    case  1:    return ::wscanf( f,a01 );
    case  2:    return ::wscanf( f,a01,a02 );
    case  3:    return ::wscanf( f,a01,a02,a03 );
    case  4:    return ::wscanf( f,a01,a02,a03,a04 );
    case  5:    return ::wscanf( f,a01,a02,a03,a04,a05 );
    case  6:    return ::wscanf( f,a01,a02,a03,a04,a05,a06 );
    case  7:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07 );
    case  8:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07,a08 );
    case  9:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07,a08,a09 );
    case 10:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10 );
    case 11:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11 );
    case 12:    return ::wscanf( f,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12 );
    }
}

Or, I could do some assembly, as I did like 15 years ago when I encountered similar (or perhaps the same) problem, but that does not feel quite right.

Can you suggest some better way?

  • 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-05-26T15:11:25+00:00Added an answer on May 26, 2026 at 3:11 pm

    As I understand it’s not an error to call a variadic function with extra (i.e. more than asked for) arguments in C (and possibly in C++, although I’ve yet to locate a definitive statement either way on that).

    The best I’ve got on the C++ side so far is 5.2.2 [expr.call]:

    A function can be declared to accept fewer arguments (by declaring
    default arguments (8.3.6)) or more arguments (by using the ellipsis,
    …, or a function parameter pack (8.3.5)) than the number of
    parameters in the function definition (8.4)

    18.10 [support.runtime] defers to the ISO C 4.8.1.1 on the subject of restrictions for va_start().

    I can’t see anywhere that says “you must not pass extra arguments”, so it seems that it wouldn’t be unreasonable to assume that it’s not prohibited.

    If it’s not legal in C++ to give extra arguments then you can use C++ to handle the default arguments still and call a C function with the defaults having been “filled out” so that you only ever call the one C function, regardless of how many arguments were given.

    So in C++ you’d do:

    extern "C" {
      int real_scanf(
            const char* format,
            void* a01, void* a02, void* a03, void* a04, void* a05,
            void* a06, void* a07, void* a08, void* a09, void* a10,
            void* a11, void* a12
            );
    }
    
    inline int scanf(
        CodingValue const* format,
        void* a01 = 0, void* a02 = 0, void* a03 = 0, void* a04 = 0, void* a05 = 0,
        void* a06 = 0, void* a07 = 0, void* a08 = 0, void* a09 = 0, void* a10 = 0,
        void* a11 = 0, void* a12 = 0
        )
    {
        BasicCodingValue const* const   f   = format->ptr();
        return real_scanf( f,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12 );
    }
    

    and then in C you could do:

    int real_scanf(
        const char* format,
        void* a01, void* a02, void* a03, void* a04, void* a05,
        void* a06, void* a07, void* a08, void* a09, void* a10,
        void* a11, void* a12
        )
    {
        return wscanf( format,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The standard specifies (23.4.4.2:5, etc.) that constructing all four ordered associative containers ( map
The standard specifies that the contents of reallocated space is undefined if the new
The Standard specifies that hexadecimal constants like 0x8000 (larger than fits in a signed
The ISO 1998 c++ standard specifies that not explicitly using a return statement in
I have a standard Button Style applied accross my application that specifies a mouseover
I am trying to find the document that specifies the standard for pthreads. I've
From section 7.3.4.2 of the c++11 standard: A using-directive specifies that the names in
The PSR-0 ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md ) standard specifies that an underscore in the class name
I know the standard specifies that it is for vectors, but what about strings?
The standard explicitly states that main has two valid (i.e., guaranteed to work) signatures;

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.