Archive

Posts Tagged ‘C/C++’

Complex initialization for a const variable

April 13th, 2013 No comments
int main()
{
    bool someFlag = false;
    const auto value = [&]{
                               if(someFlag)
                                   return -1;
                               else
                                   return 1;
                              } ();

    std::cout << "value == " << value << std::endl;
    return 0;
}

Complex initialization for a const variable

“Rule of five”

March 15th, 2013 No comments

Rule is “No copy function, move function, or destructor be compiler-generated if any of these functions is user-provided.”

New paper: N3578, Proposing the Rule of Five—Walter Brown

 

STL-containers member functions table (C++02 and C++11)

January 27th, 2013 No comments

cppreference.com: The Containers library is a generic collection of class templates and algorithms that allow programmers to easily implement common data structures like queues, lists and stacks.   There are three classes of containers — sequence containers, associative containers, and unordered associative containers — each of which is designed to support a different set of operations.

Pdf version

C9 Lectures: Core C++

July 19th, 2012 No comments

We know lots of folks are either coming back to C++, coming to C++, or have never left C++. This lecture series, in n parts, is for all of you! Only STL can make that work (novice, intermediate, and advanced all bundled together and presented in a way only STL can do.)

C9 Lectures: Stephan T. Lavavej – Core C++

“Deep C (and C++)” presentation by Olve Maudal and Jon Jagger

July 18th, 2012 Comments off

Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.

This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file.

 


Overview of Windows Runtime C++ Template Library

May 26th, 2012 No comments

The Windows Runtime C++ Template Library (WRL) is a COM-based template library that provides a low-level way to use Windows Runtime components.

The Windows Runtime is implemented by using Component Object Model (COM) technology. COM depends on reference-counting to manage the lifetime of objects, and other housekeeping techniques, and on testing HRESULT values to determine whether an operation succeeded or failed. To successfully write a COM app or library, you must carefully follow COM rules and techniques.

The Visual C++ component extensions (C++/CX) is a high-level, language-based way to use Windows Runtime components. Both the WRL and C++/CX simplify the writing of code for the Windows Runtime by automatically performing COM housekeeping tasks on your behalf.

more

Additional info: Visual C++ WinRT FAQ – WRL vs C++/CX

  • WRL is a non-extension-based ISO compliant alternative to using C++/CX when targeting WinRT. It’s fairly obvious that C++/CX is far simpler to use than WRL, specially when creating components (consuming components is relatively easier).
  • The big thing with WRL is that you can use ISO C++. You don’t have to learn a new syntactic extension that you cannot use outside the Microsoft-world. Most C++ devs would feel comfortable using WRL, specially if they’ve used ATL before. That said portability is a myth, since WRL code is as tied into Windows as would be C++/CX code.
  • Do you want to totally avoid exceptions (perhaps to remain in sync with existing code that doesn’t use exceptions)? If so, you have to use WRL since C++/CX uses exceptions.
  • Performance wise, will you see any difference? As stated above, C++/CX uses exceptions while WRL uses HRESULTs. So the performance implications of using exceptions will obviously come into play. There is also the non-trivial conversion between HRESULTs and RT exceptions. Outide of that, I don’t think there’s going to be any noticable difference in performance.
  • Not sure to what extent you can do this, but since WRL exposes the underlying COM architecture, you can fine-tune your code to some degree (since WinRT is built on top of COM). I haven’t read or heard about any scenarios where this has actually made a difference.
  • The psycological aspect. While this is the least technical of the reasons, it might be the biggest factor here. Many C++ devs would simply hate anything that they see as foreign syntax. And C++/CX is certainly not ISO C++. Its close similarity with C++/CLI (which many C++ devs found disgusting) doesn’t help either. If your C++ dev team comprises mainly of a bunch of these guys, I reckon it’d be wise to just use WRL.

 

Writing modern C++ code: how C++ has evolved over the years

September 19th, 2011 No comments
Many people think of C++ as the same language they experienced in college or just as “C with classes”, but the C++ language has evolved extensively over the years. In this session, we’ll cover how you can use C++ to write innovative, expressive and beautiful apps that deliver power and performance apps. Join us to see how the newly finished C++0x standard can make writing C++ as productive as many other languages.

Windows Runtime (WinRT)

September 16th, 2011 No comments

Windows Runtime, or shortly WinRT, is a new runtime (siting on top of the Windows kernel) that allows developers to write Metro style applications for Windows 8, using a variety of languages including C/C++, C#, VB.NET or JavaScript/HTML5.

WinRT is a native layer (written in C++ and being COM-based) that is intended as a replacement, or alternative, to Win32, and enables development of “immersive” applications, using the Metro style. Its API is object oriented and can be consumed both from native or managed languages, as well as JavaScript. At the same time the old Win32 applications will continue to run just as before and you can still (and most certainly will) develop Win32 applications.

Microsoft has created a new language called C++ Component Extension, or simply C++/CX. While the syntax is very similar to C++/CLI, the language is not managed, it’s still native. WinRT components built in C++/CX do not compile to managed code, but to 100% native code. A good news for C++ developers is that they can use XAML now to build the UI for immersive applications. However, this is not available for classical, Win32 applications.

Before you start here are several additional articles that you might want to read:

Windows Runtime reference

 


C++ clear winner in Google language tests

August 31st, 2011 No comments

Google has released a research paper that suggests C++ is the best-performing programming language in the market.

The internet giant implemented a compact algorithm in four languages – C++, Java, Scala and its own programming language Go – and then benchmarked results to find “factors of difference”.

article

Tags:

C++ Coding Guidlines

April 4th, 2011 No comments