Quantcast
Channel: Visual C++ Team Blog
Viewing all 437 articles
Browse latest View live

The Magic of Going Native 2012 Starts Today!

$
0
0

UPDATE: We are already streaming live!!

c7271438-ddbd-4e22-afbb-f500cc84afa2[1]

Are you guys ready? This is the agenda for this event happening during today and tomorrow.

Day 1 – C++11 Today


Day 2 – C++11 Today and Tomorrow

 

The event will be available for live streaming and on demand!! We’ll see you then.


C++11 Conformance Survey

$
0
0

Vikas Bhatia 

Hello, My name is Vikas Bhatia and I am a Program Manager in the Visual C++ team. We are conducting a survey to see the relative urgency of C++11 features to you, the developer.

C++11 conformance is important to us. We intend to implement the C++11 language features. We are evaluating the order with which to implement these features. We use C++ too and we know several features we think are more urgent. But instead of relying only on that, we want to check with you and let you vote on which features you think are more urgent for your needs to make sure we are in fact doing the ones most urgently needed by our customers. 

Watch Herb Sutter’s keynote at Going Native (available 24 hours after live session) where we discuss key C++11 features.

Please help us out by filling the survey link here: http://bit.ly/mscpp11

Thanks.

The Microsoft C++ Compiler Turns 20!

$
0
0

Microsoft C/C++ 7.0

This month, we enter the third decade of C++ at Microsoft.

It was twenty years ago, in February of 1992, that we released our first C++ compiler: Microsoft C/C++ 7.0. Before then, we already worked with several of the C++ “preprocessor” compilers that took C++ and converted it to C before our compiler then created the executable program. But starting in 1992, Microsoft’s premier native compiler supported C++ directly, and has done so ever since.

C/C++ 7.0 shipped in a box that was over two feet long and produced MS-DOS, Windows and OS/2 applications. It also sported the last of the character oriented development environments for C that we ever shipped – the following product was Visual C++, which built on what we had learned from delivering QuickC. Since those early days, we have shipped eleven major releases of C/C++ products (ignoring small point upgrades) for both Windows and embedded development.

This month, on the 20th anniversary of our first C++ compiler, we’re looking forward to shipping the beta of Visual C++ 11. It includes support for ARM processors, Windows 8 tablet apps, C++ AMP for heterogeneous parallel computing, automatic parallelization, and the complete ISO C++11 standard library… and a few more of the new C++11 language features too.

Last summer, we pledged to publish the C++ AMP specification as an open specification that any compiler vendor may implement, to target any operating system platform. Today, we published the C++ AMP open specification to support using C++ for heterogeneous parallel computing on GPUs and multicore/SSE today, with more to come in the future. Read the full announcement and download the specification at the Native Concurrency blog.

Finally, to make this anniversary celebration complete, we’re shifting gears to pick up speed: After Visual C++ 11 ships, you’ll see us deliver compiler and library features more frequently in shorter out-of-band release cycles than our historical 2- or 3-year timeframe. And, of course, the first and most important target of those more agile releases is to deliver more and more of the incredible value in the new ISO Standard C++11 language. Please check Herb Sutter's keynote at GoingNative 2012 for further details.

After 20 years, C++ is alive and well, and going stronger and faster than ever, not just at Microsoft but across our industry. Use it. Love it. And go native!

Reducing the Size of Statically-linked MFC Applications in VC11

$
0
0

Pat Brenner

Hello, I’m Pat Brenner, a developer on the Visual C++ Libraries team, and I am the primary developer working on the Microsoft Foundation Classes (MFC).

In Visual Studio 2010, the size of statically-linked MFC applications grew substantially. We’ve gotten a number of comments about this issue, so I wanted to post an article about the cause and the solution that we have come up with.

Cause

In Visual Studio 2010, we added a feature to the resource editor which allows you to add MFC controls to your dialogs. The MFC control types appear in the toolbox along with the standard Windows controls. Properties specific to the MFC controls can be set on them, so they behave as desired when the dialog is created.

In order for this to work properly, a DLGINIT block has to be written in the RC file for the project, which contains the properties information in binary format. The DLGINIT block has to be parsed when the dialog is being initialized, so the controls can be initialized using the information in the DLGINIT block. The code to do this parsing lives in CWnd::ExecuteDlgInit. ExecuteDlgInit method lives in WINCORE.CPP, whose object is always included in every statically-linked MFC application (because it contains the CWnd constructors and the AfxWndProc method).

The code that performs the MFC control initialization, of course, needs to know about all of the MFC controls. Those controls, in turn, may need to know about various visual managers in order to know how to draw themselves. And the visual managers, in turn, have dependencies on other MFC classes.

The result of these dependencies is that much more of MFC needs to be pulled into a statically-linked MFC application, because the linker cannot determine at build time that none of those methods will need to be called, since it all depends on the content of the RC file and DLGINIT structures inside it.

We were alerted to this size increase in statically-linked MFC applications shortly before the release of Visual Studio 2010 RTM, but we were not able to definitively establish the cause before Visual Studio 2010 shipped. Even if we had, we most likely would not have been able to put the finishing touches on a solution before the release date, because we had to try several different approaches before arriving at a working solution that puts a very small requirement on the MFC developer.

Solution

To fix the problem, we eliminated a number of dependencies between MFC classes (further details are below). We also moved several methods that have an effect on the MFC control initialization:

  • CWnd::ExecuteDlgInit, DDX_Control, AfxRegisterMFCCtrlClasses
  • CMFCControlContainer::SubclassDlgControls and CMFCControlContainer::PreUnsubclassControl

into separate source modules.

These separate source modules are then compiled in two different ways:

  • With _AFX_NO_MFC_CONTROLS_IN_DIALOGS not #defined, they are built into the standard static MFC libraries, NAFXCW[d].LIB and UAFXCW[d].LIB, with the standard behavior enabled.
  • With _AFX_NO_MFC_CONTROLS_IN_DIALOGS #defined, they are built into a new small static MFC library, AFXNMCD[d].LIB, without the ability to initialize MFC controls on dialogs. (The NMCD in the library name is an acronym for “No MFC Controls on Dialogs”.)

The new smaller library has the same methods (same names, but different implementations) as the larger standard MFC libraries, so we must make sure to link it in first. This ensures that the functions that don’t have any dependency on MFC control initialization are used and the dependencies are eliminated. This is accomplished via symbols that are defined in the new source modules, and force-included via #pragma statements in AFX.H based on #defines set.

The result of this work is that you can simply #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS in your MFC application’s stdafx.h file, and all the code that performs MFC control initialization on dialogs will be left out of your application. In a simple dialog-based application, this will reduce the size of the application by approximately 80%. [Note that if you do use MFC controls on a dialog, and build with _AFX_NO_MFC_CONTROLS_IN_DIALOGS #defined, your application may not run at all (or dialogs will not appear) because a dialog containing a nonexistent window class cannot be created. We added TRACE statements to MFC to this effect to help point out this issue.]

In addition, we have made changes in the code generated by the MFC application wizard. It will generate code that contains #ifdefs for the _AFX_NO_MFC_CONTROLS_IN_DIALOGS, so:

  • Dialogs will be derived from CDialog instead of CDialogEx if the #define is set.
  • No CShellManager will be created in the application’s InitInstance method if the #define is set.

We have implemented these changes in MFC for the next major release of Visual Studio. Now that we understand the cause and the best solution, we looked at the possibility of porting the changes back to Visual Studio 2010 in order to benefit applications built with that version. Unfortunately, the changes we made to reduce the dependencies between MFC classes included:

  1. Moving D2D-related member functions/data out of the _AFX_GLOBAL_DATA class to a separate class
  2. Adding a new virtual method to both CMDIChildWnd and CMDIChildWndEx
  3. Adding a new method to the CWinApp class

Because these changes introduce binary incompatibilities, we are not able to port the changes back to Visual Studio 2010 without breaking existing MFC applications.

I hope you find this information helpful!

 

 

Pat Brenner
Visual C++ Libraries Development

GoingNative 2012 Online

Help Us Make Improvements

$
0
0

The Microsoft Visual Studio Design Research Team is looking for developers to give us direct feedback on our development tools, languages and libraries! Opportunities include usability studies of upcoming features, focus groups where we explore new ideas, as well as 1:1 interviews.

Is this just about Visual Studio users?

You do NOT need to be a Visual Studio user! We are looking for all kinds of developers using a variety of tools and technologies.

What do participants get out of it?

Because we do many studies across all of our development tools, we always try to match participants’ skill sets to the area we are studying. If you are selected to participate in one of our research studies, benefits include a combination of the following:

  • A chance to see and use upcoming tools, features, and language/library enhancements,
  • Interact directly with members of our development teams to discuss your requirements for efficient and effective tools,
  • Influence future design decisions, and
  • If you reside in the U.S. you receive a choice of a Microsoft product from our gratuity list!

We have a brief enrollment form that will ask you a few questions about your job and the development tools and technologies you actively use. We will contact you as soon as we have a research study that matches your specific background and/or interests.

This enrollment should only take 3-5 minutes to complete.

If you have any questions about participating, please feel free to contact vsdr@microsoft.com. To learn more about how we help protect your privacy visit our corporate privacy page. We are sorry, but government employees are not eligible to receive gratuities. However, we would still like you to participant in our studies.

[Go to the Enrollment Page]

C++ Precon at Tech Ed 2012 – Orlando and Amsterdam

$
0
0

At both Tech Ed North America 2012 (June 11th-14th) and Tech Ed Europe 2012 (June 26th-29th) there will be a C++ all day preconference! The title is C++ in 2012: Modern, Readable, Safe, Fast. Our C++ MVP Kate Gregory will deliver it and here's the abstract:

C++ is gaining momentum as a development language, so whether you’ve never used C++ or stopped using it a decade ago, it may be time to brush up on your skills. With a new standard release providing new keywords and capabilities, C++ is a  featured language for many of the new Microsoft technologies and enables some amazing speed-ups of your application using libraries like PPL and C++ AMP. What’s more, Visual Studio offers tools to native developers that have only been available for managed developers in earlier versions. This all-day session will show you what all the fuss is about and give you the skills you need to understand the advantages of C++ today and how to start applying those benefits to your application.

There are three main categories of attendees who would enjoy this session:

 

  • It’s perfect for those who used C++ a long time ago and need a refresher, a way to catch up with all that has happened to C++ in the last ten years.
  • Developers who have never written a line of C++ code, but are solid in C# or Java will know the basic syntax (if, while, etc) and be able to follow this session and see why there is so much excitement around C++ these days.
  • C++ developers who are not using Visual Studio and not developing for Windows can come and see how their C++ skills will translate to these technologies and how quickly they can be productive on a new platform.

This preconference is technical and has lots of code in it. It’s not an “introduction to C++” that starts from scratch. It’s about providing the inspiration you need to start using particular features and starting writing modern C++. While you’re at TechEd, you can also attend some C++ breakout sessions to go deeper into particular technologies and tools that caught your interest. If you watched the sessions from the GoingNative 2012 conference, and could follow them, you know how much C++ programming has changed this century. If not, and you’re curious what the buzz is about, come and find out! It’s a great way to start your TechEd experience, June 10th in Orlando or June 25th in Amsterdam. We’ll see you there!

What's New in Visual Studio 11 Beta for C++ Developers

$
0
0

 

XAML <TextBox x:Name="textbox"/>
C++
textbox->Text =
"Hello World!";
Output A Metro style HelloWorld.cpp

Snippets of the Metro style version for the most popular 101 application.

 

 

 

Download this Beta today:

 

 

 

As Jason Zander –CVP of Visual Studio- just confirmed, a Visual Studio 11 Beta was released earlier today.

What can C++ developers expect from this new version compared to Visual Studio 2010? Here's a summary:

  • Windows 8:
    • Support for Metro style apps using native C++ code.
    • C++ Metro style applications can create new UI using DirectX and/or the completely-new all-native XAML UI framework for Windows 8.
    • C++ developers can also create components that extend Windows 8 apps written in HTML5/JavaScript.
  • C++11:
    • New core language features: range-based for-loop, override/final, and strongly-typed/forward-declared enums.
    • More core language features to follow shortly after Visual Studio 11.
    • New Standard Library headers: <atomic>, <chrono>, <condition_variable>, <future>, <mutex>, <ratio>, <scoped_allocator>, and <thread>.  Also <filesystem>.
    • Emplacement methods have been implemented in all containers for "arbitrary" numbers of arguments.
    • Simulated variadic templates now accept a maximum of 5 arguments by default, down from 10.  To increase this limit, at the cost of compiler speed, define _VARIADIC_MAX project-wide between 5 and 10 inclusive.
    • Per-container and per-element memory consumption has been optimized.
  • Code Performance and Parallelism:
  • IDE Enhancements:
    • Code understanding enhancements like semantic colorization and reference highlighting.
    • Editing enhancements like proactive IntelliSense, member list filtering and code snippets.
  • Application Lifecycle Management (ALM) -not in Herb’s post:
    • Comprehensive tools like dependency diagrams and the Architecture Explorer.
    • Testing tools like a new Unit Testing Framework and Code Coverage.
    • Static Analysis for a better diagnosis of coding errors even if the compilation is okay.

 

 

 

Links of interest:


What’s up with MFC in Visual Studio 2011 Beta

$
0
0

Pat Brenner

Hello, I’m Pat Brenner, a developer on the Visual C++ Libraries team. Through this blog post I wanted to share some information about the Microsoft Foundation Class (MFC) Library, since I am the primary developer working on MFC.

As you know, MFC is an important technology component which has been extensively used over the years by C++ developers to build desktop applications for Windows. In every product release, we make enhancements to the library, whether it is taking advantage of features in newer versions of the Windows operating system or adding fixes for common developer issues. With the recent release of Visual Studio 11 Beta, there have been some concerns among the MFC developers about the apparent lack of focus on MFC.

In every release we need to balance our investment across the various areas of the product. However, we still believe that MFC is the most fully-featured library for building native desktop applications. We are fully committed to supporting and maintaining MFC at a high level of quality. Here’s a short list of some of the issues that we fixed in MFC for Visual Studio 11:

  • Addressed executable size of applications linked statically to MFC
  • Fixed DLLMain best practices violations by deferring initialization of the afxGlobalData structure
  • Fixed over 220 bugs, nearly 100 of which were reported by customers via the Connect web site
  • Fixed a large number of paint/draw issues (in toolbars, splitters, theme switches, etc.)
  • Fixed several memory leaks (in CMFCVisualManager and CMFCButton classes)
  • Added a number of missing exports (methods and data) to the MFC import libraries

In addition to this, the Visual C++ teams have invested significantly in enabling C++ developers to natively build Metro style applications for Windows 8 (through compiler, libraries and productivity features). This is the primary reason that in this release MFC didn’t receive as much attention as in previous Visual Studio releases.

We don’t know yet what the future investments for feature additions in MFC would be. However, we’re committed to supporting MFC and making sure that applications built on it will run on future Windows platforms. I hope you find this information useful and reassuring.

 

Pat Brenner
Visual C++ Libraries Development Team

What’s New in Code Analysis for Visual Studio 11

$
0
0

 The Code Analysis team has just posted an article on the latest improvements in Visual Studio 11. If you are a C++ developer (we guess you are as you are reading this blog), it’s worth taking a look.

[Read the article here]

Setting WINVER for MFC Applications

$
0
0

Pat Brenner

Hello, I’m Pat Brenner, a developer on the Visual C++ Libraries team, and I am the primary developer working on MFC.

I’ve realized over the course of the past several years that a number of developers (especially those using ATL and/or MFC) can be confused about the proper usage and setting of the WINVER #define (and/or the corresponding _WINNT_WIN32 and NTDDI_VERSION #defines). This setting is especially important when building an application that supports multiple Windows platforms, as MFC itself does. So I would like to suggest a best practice for how these #defines should be set when building an MFC application for multiple platforms.

Build time settings

At build time, you should not #define WINVER (or _WINNT_WIN32 or NTDDI_VERSION) to the lowest platform you want to support. This will keep you from using the latest APIs and structures available to you, and keep you from handling the latest Windows messages. Instead, you should #define WINVER (or _WINNT_WIN32 or NTDDI_VERSION) to the highest platform that you want to support. This will ensure that you have available the latest APIs, messages, and structures, so that your application can make use of all of the capabilities that the newest platforms have to offer. This is the way that MFC itself is built—this way we can add handlers for the latest Windows messages and use the latest Windows APIs. For example, MFC 10.0 (which shipped with Visual Studio 2010) supported Windows XP as the lowest platform, but also supported features only available in Windows 7, like live taskbar display of multiple MDI window contents.

Run time behavior and checking

At run-time, however, you need to ensure that your application will run on your lowest supported platform. This means that you cannot call an API available only on newer platforms directly, because calling the API directly will result in an “import not found” message on the older platform and your application will simply not start. Instead, you must dynamically load (via LoadLibrary/GetProcAddress) any API that is supported only on newer platforms. For example, MFC does this when using the D2D APIs. Here’s an example from the current version of MFC—see the InitD2D method of the _AFX_D2D_STATE class in module AFXRENDERTARGET.CPP provided with Visual Studio 11 Beta:

 

m_hinstDWriteDLL = AtlLoadSystemLibraryUsingFullPath(L"DWrite.dll");
if (m_hinstDWriteDLL != NULL)
{
    auto pfD2D1CreateFactory = AtlGetProcAddressFn(m_hinstDWriteDLL, DWriteCreateFactory);
    if (pfD2D1CreateFactory)
    {
        hr = (*pfD2D1CreateFactory)(writeFactoryType, __uuidof(IDWriteFactory), (IUnknown**)&m_pWriteFactory);
    }
}

 

Note the use of the AtlLoadSystemLibraryUsingFullPath helper (whose implementation is in ATLCORE.H), which will ensure that the “system” DLL is loaded only from the correct Windows library folder. Also note the use of the AtlGetProcAddressFn macro (whose definition is in ATLDEF.H), which will call GetProcAddress using the correct function prototype.

You also must ensure that you are not calling any Windows API with a structure that is larger than it expects, because it may simply fail. Make sure that you understand the structure size that the API is expecting on that platform and use that size. For example, MFC does this when sending tool-tip messages. Here’s a (slightly modified) example from the current version of MFC—see the HitTest method of the CToolTipCtrl class in module TOOLTIP.CPP, and the definition of the AFX_OLDTOOLTIPINFO structure in AFXIMPL.H, provided with Visual Studio 11 Beta:

 

TTHITTESTINFO hti = {};
hti.ti.cbSize = sizeof(AFX_OLDTOOLINFO);
hti.hwnd = pWnd->GetSafeHwnd();
hti.pt = pt;

if (::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti))
{
    Checked::memcpy_s(lpToolInfo, sizeof(*lpToolInfo), &hti.ti, sizeof(AFX_OLDTOOLINFO));
    return TRUE;
}

Cautions

Please note that you do have to be careful when using this approach. It is very easy to end up using an API that is only available on a later platform, only to find that when your customers try to run your application on an older platform, it won’t even run. When your application tries to load a non-existent API from a system DLL at startup (when the import table is being initialized), it will fail, and an error message to the effect of “import not found” will be issued. So make sure to test your application on all supported platforms to make sure that it is compatible.

It is only necessary to follow this recommended practice when building an application that is expected to support multiple Windows platforms. If your application only needs to support a single platform, you can set WINVER (or the corresponding other #defines) to the value that matches that platform. This way you are sure to use only the APIs and other features that are available on that platform.

I hope you find this information helpful. Please feel free to respond with any questions you may have.

 

Pat Brenner
Visual C++ Libraries Development

VC11 ISO C++ Concurrency Tour in March Issue of MSDN Mag

$
0
0

Diego DagumGreetings!! I am Diego Dagum, Community Program Manager with the Visual C++ team.

I recently got an article published in the current issue of MSDN Magazine about the ISO C++11 concurrency features implemented in Visual C++ 11.

 

 

It’s a 101-level journey through standardized features like:

  • Asynchronous tasks.
  • Threads.
  • Promises and futures.
  • Thread-bound variables -not really implemented in VC11 but I show how to simulate them.
  • Exceptions.
  • Atomic types.
  • Mutual exclusion objects (mutex) and locks.
  • Condition variables.

[Read “New Standard Concurrency Features in Visual C++ 11” at the MSDN Magazine website]

 

If you want to dig further in these items, I recommend the video tutorial that my friend Bartosz Milewski is posting in the Corensic website. He covers advanced concepts like passing arguments to threads or dealing with data races. At the time of writing this post, his tutorial already contains 9 parts. Bartosz says that there are more episodes coming soon.

 

Enjoy!!

Using the Windows Software Development Kit (SDK) for Windows 8 Consumer Preview with Visual Studio 2010

$
0
0

Now that the Windows Software Development Kit (SDK) for Windows 8 Consumer Preview has been released, I would like to show you how you can use the Windows 8 SDK with Visual Studio 10.

 

  • Download and install the SDK from http://msdn.microsoft.com/en-us/windows/desktop/hh852363.
  • Note the location of your Win8 SDK install – by default it is %PROGRAMFILES%\Windows Kits\8.0\
  • Open your project in VS 2010.  The instructions to do this in VS11 with the v100 platform toolset are similar and you may try that out as well, but these instructions below show how to do this in VS 2010.
  • For each project where you want to use the Windows 8 SDK, go to project properties, VC++ Directories

 

  • Change the following properties (if you installed the SDK to a different location, replace the SDK path with your custom install location):

-          In “Executable Directories” replace $(WindowsSdkDir)bin with $(ProgramFiles)\Windows Kits\8.0\bin\x86

-          In “Include Directories” add $(ProgramFiles)\Windows Kits\8.0\Include\um;$(ProgramFiles)\Windows Kits\8.0\Include\shared at the beginning and remove $(WindowsSdkDir)include

-          In “Library Directories” replace $(WindowsSdkDir)lib with $(ProgramFiles)\Windows Kits\8.0\lib\win8\um\x86

-          In “Exclude Directories” replace $(WindowsSdkDir)include with $(ProgramFiles)\Windows Kits\8.0\Include\um;$(ProgramFiles)\Windows Kits\8.0\Include\shared

-          When targeting x64, replace x86 with x64

 

That’s it – you should be ready to build and run!

 

Alex Thaman

Senior Test Lead

Visual C++ Team

Microsoft Corp.

Auto-Vectorization on Channel9

$
0
0

Jim Radigan and I recorded a session for Channel9 last week, as part of the “Going Native” series.  We describe the “auto-vectorizer” – a neat feature in the VS11 compiler backend that analyses loops, in regular, unmodified C++ code, and generates corresponding vector (SIMD) instructions: tight loops using float or int can run up to 4x faster.  The video has just “gone live” at:

http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-7-VC11-Auto-Vectorizer-C-NOW-LangNEXT

What Are SCARY Iterators?

$
0
0

Diego DagumHi there! I’m Diego Dagum, a Program Manager with the Visual C++ team.

As Stephan announced last September when Visual Studio 11 Developer Preview was released, our STL implementation comes with SCARY iterators. On Stephan’s words,

”(…) as permitted but not required by the C++11 Standard, SCARY iterators have been implemented, as described by N2911 "Minimizing Dependencies within Generic Classes for Faster and Smaller Programs" and N2980 "SCARY Iterator Assignment and Initialization, Revision 1.

What are they useful for? What are they, in the first place? What’s so SCARY about them?

In this post I’ll demystify any mystery about SCARY iterators, hopefully inspiring in you some design best practice for your own template classes.

 

 

 

Imagine the following situation:

  1. // the list below uses an allocator other than the default
  2. list<int, stdext::allocators::allocator_unbounded<int>> l;
  3.  
  4. // Is the following line valid? (i.e. does it compile?)
  5. list<int>::iterator iter(l.begin());

 

Does it compile or not? Well, I tried to compile that code using a pre-v11 Visual C++ compiler, getting the following error:

  1. error C2664: 'std::_List_iterator<_Mylist>::_List_iterator(const std::_List_iterator<_Mylist> &)' : cannot convert parameter 1 from 'std::_List_iterator<_Mylist>' to 'const std::_List_iterator<_Mylist> &'
  2. 1>          with
  3. 1>          [
  4. 1>              _Mylist=std::_List_val<int,std::allocator<int>>
  5. 1>          ]
  6. 1>          and
  7. 1>          [
  8. 1>              _Mylist=std::_List_val<int,stdext::allocators::allocator_unbounded<int>>
  9. 1>          ]
  10. 1>          and
  11. 1>          [
  12. 1>              _Mylist=std::_List_val<int,std::allocator<int>>
  13. 1>          ]
  14. 1>          Reason: cannot convert from 'std::_List_iterator<_Mylist>' to 'const std::_List_iterator<_Mylist>'
  15. 1>          with
  16. 1>          [
  17. 1>              _Mylist=std::_List_val<int,stdext::allocators::allocator_unbounded<int>>
  18. 1>          ]
  19. 1>          and
  20. 1>          [
  21. 1>              _Mylist=std::_List_val<int,std::allocator<int>>
  22. 1>          ]
  23. 1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

 

The reason I’ve got this error is that in the last line of the code I’m trying to initialize iter (an iterator over a list of int using the default list allocator std::allocator<int>) with an iterator which looks similar excepts that it corresponds to a list allocated by the alternative stdext::allocators::allocator_unbounded<int>. Sad but true, these are different specializations of list of ints; therefore, conversions between them can’t be handled by default.

From a compiler perspective there is nothing wrong here. From a practical standpoint, however, there isn’t any semantic dependence between list iterators and list allocators. And, in general for all STL containers, iterators only depend (semantically speaking) on the container element type.

Based on research paper N2911 "Minimizing Dependencies within Generic Classes for Faster and Smaller Programs", the acronym SCARY describes

Assignments and initializations that are Seemingly erroneous (appearing Constrained by conflicting generic parameters), but Actually work with the Right implementation (unconstrained bY the conflict due to minimized dependencies)

… or just SCARY, you know... (Don’t kill the messenger, I wasn’t the inventor of this name!)

 

In our STL11 implementation, iterator dependencies were minimized so the precedent code compiles fine. The same applies for any other STL container iterator (vector, deque, etc.) This said, you’ll be able to implement novel algorithms in ways that were previously impossible due to type mismatches. Not that scary, after all!

 

 

 

Epilogue

The issue that prevented my program to compile isn’t just tied to a particular STL implementation. In fact, as N2911 "Minimizing Dependencies within Generic Classes for Faster and Smaller Programs" tells, it's a more general issue that can happen when designing generic classes. In its authors’ own words:

We advocate a design principle whereby the dependencies between the members and the type parameters of a generic class should be minimized, we propose techniques to realize this principle, and we show that the principle can be leveraged to achieve faster and smaller programs.

Worth reading. Enjoy!

 

PS. A HUGE THANKS to Stephan T. Lavavej (Mr. STL) for reviewing this post.


Early Bird registration for C++ Now! ends Sunday

$
0
0

image

(A message on behalf of the C++ Now! staff)

 

This year’s program is very exciting with lots more content than previous years. This year we’ll have three keynotes: Howard Hinnant, Sean Parent, and David Vandevoorde. They are headlining three tracks of over fifty sessions including one track of C++11 sessions. With almost a full week of C++11 tutorials, we are offering more C++11 coverage than any other conference this year.

Please join us for what promises to be one of the best BoostCons ever!  Visit

http://cppnow.org/ to register today.

Auto-Vectorization

Target Windows XP in Visual Studio 11 Beta using the Visual Studio 2010 compiler and libraries

$
0
0

In my previous blog I talked about how in Visual Studio 11 we have eliminated the need to convert your Visual Studio 2010 C++ projects in order to adopt the new IDE. The blog also mentioned that you can build your projects using Visual Studio 2010 compiler (tools and libraries) from within Visual Studio 11 using the multi-targeting feature. This means while you adapt to using the new compiler and while your 3rd party vendors provide you with binaries compatible with the Visual Studio 11 compiler (tools and libraries) you can leverage the new Visual Studio 11 IDE without disrupting your ship cycle. Just set the platform toolset property to v100 in the property pages (requires Visual Studio 2010 to be installed side-by-side with Visual Studio 11). Since no upgrade of your project file is necessary you can continue to load the project/solution in Visual Studio 2010 as well.

We have recently received feedback from a number of customers about the inability to build binaries that run on Windows XP with the Beta version of the Visual Studio 11 compiler and libraries. This is because the C++ compiler and libraries in Visual Studio 11 Beta leverages platform capabilities only available in Windows Vista and higher. However, if support for Windows XP targeting is important to you, then you can use Visual Studio 11 Beta’s multi-targeting capability described above in order to employ the Visual Studio 2010 compiler and libraries to build applications and libraries than execute on Windows XP. This enables you to enjoy the new features of the Visual Studio 11 Beta environment without sacrificing backward compatibly in your applications!

Thanks,

Amit Mohindra

C++Team

Building Windows 8 Metro style apps with C++ Windows camp

$
0
0

Hello all,

We’re hosting a one day, free technical event in Redmond on May 18, 2012 intended for developers who want to write Metro apps for Windows 8 with C++.

 

Details:
Location:
Redmond WA, Microsoft campus, bldg 92.
Date:  May 18th, 2012
Time:  9 AM to 5 PM for sessions, Q&A and a small social event afterwards.
Speakers:  We will update the list of speakers early next week, we are still negotiating session times & speakers to cram as much as we can into a single day.  Rest assured most of them are from the product team and yes, Herb Sutter will do the opening keynote and the first session.
Meals:  We will have some light breakfast, lunch, snacks and appetizers + drinks at the end of the day.

These Windows-specific talks will use both portable ISO C++ and Visual C++-specific compiler extensions; for brevity below we'll refer to both as "C++" (i.e., this day is about Visual C++, not Visual C#/VB or JavaScript).


If you are a new C++ developer wanting to learn about the writing Metro style apps, an intermediate developer looking to reuse their C++ code and skills, or an experienced C++ developer looking to squeeze every ounce of performance out of your Metro style app, this event is for you. We will have pragmatic advice for every developer writing Metro style apps and games with XAML or DirectX and C++

Register for the event here!

Agenda

  • C++ for Windows 8, Keynote by Herb Sutter
  • Building Windows 8 apps with XAML and C++
  • Building Windows 8 games with DirectX and C++
  • Introduction to the Windows Runtime Library (WRL)
  • Writing Connected apps: Writing networking code with C++
  • Combining XAML & Direct X in a Metro style apps
  • Writing WinRT components to be consumed from any language
  • VC11 compiler flags for getting the most out of C++

Please spread the word.

 

Thanks,

Vikas Bhatia

VC++ PM

Announcing Casablanca, a native library to access the cloud from C++

$
0
0

Our devices are becoming increasingly connected, and at the same time our customers expect the applications running on those devices to be fast and fluid. Asynchrony is important on the client for responsiveness and on the server for scalability.

Today we are announcing Casablanca, a Microsoft incubation effort to support cloud based client-server communication in native code using a modern asynchronous C++ API design. Casablanca is a project to start exploring how to best support C++ developers who want to take advantage of the radical shift in software architecture that cloud computing represents.

If you are a developer writing a responsive client app, or a scalable server-side solution, where asynchrony goes hand in hand with parallelism, you should give Casablanca a try.

Here’s what you get with Casablanca:

  • Support for accessing REST services from native code on Windows Vista, Windows 7 and Windows 8 Consumer Preview by providing asynchronous C++ bindings to HTTP, JSON, and URIs
  • A Visual Studio extension SDK to help you write C++ HTTP client side code in your Windows 8 Metro style app
  • Support for writing native-code REST for Azure, including Visual Studio integration
  • Convenient libraries for accessing Azure blob and queue storage from native clients as a first class Platform-as-a-Service (PaaS) feature
  • A consistent and powerful model for composing asynchronous operations based on C++ 11 features
  • A C++ implementation of the actor-based programming model inspired by Erlang.
  • A set of samples and documentation

We have released Casablanca on devlabs to get feedback from you on what you think your needs are and how we can improve. Please use the forums to give us feedback.

We are also releasing a survey to learn more about you and get feedback from you on how we could improve Casablanca. Please help us out by filling the survey link here: http://bit.ly/casablancacpp

Here are a few links

 

Thanks,

The Casablanca team

Viewing all 437 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>