C11 and C17 Standard Support Arriving in MSVC

0
Avatar

Elnar

Please look our Visible Studio 2019 version 16.8 Preview 3 unlock notes for added of our most as a lot as date facets.

Our crew is blissful to lisp that C11 and C17 are turning into supported language versions in the MSVC compiler toolset beginning with Visible Studio 2019 version 16.8 Preview 3!

For a selection of years Visible Studio has preferrred supported C to the extent of it being required for C++. Things are about to change now that a conformant token-primarily primarily primarily based preprocessor has been added to the compiler. With the advent of two unusual compiler switches, /std:c11 and /std:c17, we are officially supporting the most as a lot as date ISO C language requirements.

What’s in:

The total required facets of C11 and C17 are supported. This meant along side the following functionalities:

  • _Pragma
  • restrict
  • _Noreturn and
  • _Alignas, _Alignof and
  • _Generic and toughen
  • _Static_assert

IntelliSense works natively with these facets as properly, simply exhaust a .c file extension to your supply info or the /TC compiler switch to enable syntax highlighting for C code.

Currently IntelliSense highlighting is preferrred on hand for the major phrases and now not the macros introduced by the fashioned headers. This would presumably well presumably also be mounted in a later unlock.

Since C17 is essentially precise a computer virus repair unlock of ISO C, with many defect experiences being adopted, our toughen for C11 already involves all the associated defect experiences. In the intervening time, there aren’t any differences between the C11 and C17 versions other than for the __STDC_VERSION__ macro, which expands to 201112L (for C11) and 201710L (for C17).

Right here is an instance that reveals these facets:

#embody  
#embody  
#embody  
#embody  

#interpret NO_WARN(X)                                                  
    _Pragma("warning (push)") _Pragma("warning (disable: 4146)") X; 
    _Pragma("warning (pop)") 

// Take kept or storei in response to the variety of the dst 
#interpret retailer(x, y) _Generic((x),               
                            records*: kept,      
                            int: storei)(x, y) 

typedef struct records {
    _Alignas(8) unsigned int i;
} records;

static_assert(alignof(records) == 8, "records is now not properly aligned");

void kept(recordsrestrict dst, const recordsrestrict src)
{
    // Carry out now not role off warning 4245 
    dst->i = NO_WARN(-(src->i));

}

void storei(intrestrict dst, const intrestrict src)
{
    *dst = *src;
}


noreturn void my_exit(int ret) {
    exit(ret);
}

int major() {
    records src, dst;
    src.i = 5;

    int i, j;

    i = 10;

    retailer(&src, &dst);
    retailer(&i, &j);

    my_exit(0);
}

For the reason that inclusion of the token-primarily primarily primarily based conformant preprocessor, the two unusual C compiler switches imply /Zc:preprocessor. In case you might per chance presumably well presumably contend with to make exhaust of the outdated, character-primarily primarily primarily based preprocessor alongside C11 or C17, you can favor to cross in the /Zc:preprocessor- compiler switch explicitly. We enact succor you to repair your supply code where wished to now not rely on the legacy, outdated preprocessor.

What’s now not:

While there’s in the meanwhile no toughen for any C11 non-obligatory facets, we are dedicated to providing the most impactful non-obligatory facets in future releases. Atomic and threading toughen are on our roadmap. Toughen for Complex numbers is in the meanwhile now not planned and their absence is enforced with the coolest fair test macros. Please hunch to Visible Studio Developer Group and suppose your toughen for facets you contend with to be applied. We are seeking out your enter that we are making the edifying prioritizations.
Attributable to the character of the Windows heap, aligned_alloc toughen is missing. The different is to make exhaust of _aligned_malloc.

Moreover, DR 400 toughen is in the meanwhile unimplemented for realloc as this switch would destroy ABI.

Variable Length Arrays

Astute readers will video display that VLAs are also now not supported. Variable dimension arrays are most steadily much less ambiance correct than associated mounted sized arrays, and most steadily inefficient when in contrast with equal malloc(), when safely and securely applied. VLAs present assault vectors equal to these of the contaminated will get() — deprecated and destined to removal — for opportunities of “transferring the stack” and varied exploits. For these causes we intend now to now not toughen VLAs as an non-obligatory fair in C11.

C11 and C17: Getting Began

In expose to make exhaust of C11 or C17 on your functions, the most as a lot as date Windows SDK updates are required to work properly with the conforming preprocessor (/Zc:preprocessor), and the unusual Universal C Runtime. Windows SDK releases correspond with Windows OS releases. Since there turned into no Windows unlock with these changes, you can need an Insider Preview Windows SDK – a preview version of the Windows SDK that corresponds with Windows builds in the meanwhile being flighted for Windows Insiders. Present that after putting in the Insider Preview Windows 10 SDK, Visible Studio initiatives configured to make exhaust of the most as a lot as date Windows SDK will exhaust the Insider Preview.

Step 1: Log in with an Insider Microsoft Yarn

Any individual can salvage a free Microsoft chronicle (https://signup.live.com/) after which opt into the Insider program. Merely hunch to https://insider.dwelling windows.com/en-us/for-builders and click on ‘Register’ and log in.

After registering, you might be given the selection to birth out flighting Insider versions of Windows, but here is now not wanted to download and exhaust the Insider Windows 10 SDK. Registering doesn’t routinely opt on your machines to download unusual Windows flights.

If you hit this web page, you enact now not favor to click ‘Flight now’. Proceed to the next step and download the Insider Preview Windows 10 SDK.

Step 2: Download the Insider Preview Windows 10 SDK

The Insider Preview Windows SDK might per chance presumably well just be installed from https://www.microsoft.com/en-us/tool-download/windowsinsiderpreviewSDK. If here is now not the web page you receive, be certain which that you just would be succesful to very properly be logged in along with your Microsoft chronicle that has been opted into being an Insider.

The Insider web page describes that the exhaust of a Windows 10 Insider Preview OS is required. This is precise for some of the enlighten included in the Windows SDK, as they might be able to just rely on unusual APIs now not video display on older versions of Windows, however the Windows and Universal C Runtime headers will properly set up and be usable without an Insider OS.

Click on ‘Gain SDK Insider Preview – Produce 20206’ to birth out download. Future versions of the Windows SDK will also work.

Step 3: Install the Insider Preview Windows 10 SDK

The Insider Preview Windows SDK will download as an .iso file.

Mount the .iso file and scoot WinSDKSetup.exe to birth out installation.

Want to set up the Windows Tool Model Equipment on this pc and click on next. You’ve got gotten to procure whether or now to now not allow insights for Windows SDK utilization and must settle for the license settlement ahead of you reach at the fair installation web page. The correct facets it is best to set up (except that you just would be succesful to very properly be the exhaust of an Insider Preview produce of Windows 10) are:

  • Windows SDK Signing Instruments for Desktop Apps
  • Windows SDK for UWP Managed Apps
  • Windows SDK for UWP C++ Apps
  • Windows SDK for Desktop C++ x86 Apps (if planning on constructing for x86)
  • Windows SDK for Desktop C++ amd64 Apps (if planning on constructing for amd64)
  • Windows SDK for Desktop C++ arm Apps (if planning on constructing for arm)
  • Windows SDK for Desktop C++ arm64 Apps (if planning on constructing for arm64)

The SDK will contend with a couple minutes to total installation after which you might per chance presumably well presumably launch Visible Studio 16.8 Preview 3.

Step 4: Configuring C11 or C17 mode in Visible Studio 16.8 Preview 3

Toughen for C11 and C17 begins in Visible Studio 16.8 Preview 3. You might per chance presumably well presumably presumably download the most as a lot as date Preview by way of https://visualstudio.microsoft.com/vs/preview/.

For your project, launch the Properties web page. First, we are seeking to advise that that the project will exhaust the Insiders Preview Window 10 SDK. Space Windows SDK Model to 10.0.20206.0 (or the most as a lot as date Insider Preview Windows 10 SDK precise installed).

You will likely be succesful to also look a brand unusual option: C Language Long-established. Space this to ISO C11 Long-established (/std:c11) or ISO C17 (2018) Long-established (/std:c17).

The C++ Language Long-established is used when the language is C++ – this might per chance per chance presumably well just be the default when the file extension is .cpp. The C Language Long-established version is used when the language is C – this might per chance per chance presumably well just be the default when the file extension is .c. To be certain that the project is constructing with C11 or C17, it’s good to advise that it is a .c file, or role the code to compile as C in the Properties tab.

After these project changes, you’re in a position to test out C11 and C17!

In Conclusion

We are very enraged to at closing toughen C11 and C17! Because the preferrred voted Developer Group suggestion, we’re certain you’re enraged too. In case you might per chance presumably well presumably adore toughen for the non-obligatory facets of C11, please dispute us on Developer Group.

As repeatedly, we welcome your feedback. We might per chance presumably well just be reached by way of the feedback under or by way of email (visualcpp@microsoft.com). In case you reach upon problems with Visible Studio or MSVC, or possess a proposal for us, please dispute us through Support > Send Suggestions > File A Discipline / Present a Recommendation in the product, or by way of Developer Group. You might per chance presumably well presumably presumably moreover fetch us on Twitter (@VisualC).

Read More

Leave A Reply

Your email address will not be published.