New Age C++
Going Mobile with C++
A survey of the emerging mobile landscape, and how C++ fits in.
I'm going to take a break from code this month and focus on an increasingly important topic to C++ developers: The rise of tablets and smartphones (and the corresponding PC sunset), and how C++ fits in.
A 'Techtonic' Shift
When Steve Jobs proclaimed in June 2010 that the post-PC era had begun, some thought that he exaggerated. But today the Wintel consortium has just a 35 percent share of computing device shipments. Recently, IDC and Gartner Inc. have reported that PC sales keep falling, even after the Windows 8 launch. And other recent research predicts that the total PC installed base will be eclipsed by smartphones and tablets by mid-2013.
One driving force behind this disruption is the rise of app stores, which decreases the cost of delivering independent apps to users. In this new sales channel, an ecosystem of spontaneous "appreneurs" (application entrepreneurs) is taking the role once occupied by well-established independent software vendors (ISVs).
Apple Inc. and Google Inc. have taken a huge early lead here. Their app stores have, by far, the most apps; those apps, in turn, fuel device sales. They've been so successful that both companies have surpassed Microsoft in market capitalization.
These days, Microsoft, Nokia Corp. and BlackBerry maker Research In Motion Ltd. are struggling to carve out a niche as the third ecosystem.
How C++ Fits in the Post-PC Scenario
ARM, a low-power-consuming system on a chip (SoC), is the "Intel inside" of the post-PC era. It's more limited than the traditional x86/x64 architecture, but more efficient in terms of battery life. With the new chips, C++ gets a shot in the ARM because it runs directly on that limited hardware. Thus, C++ apps provide greater battery life than Java- and .NET-created apps, because those apps' VMs burn extra CPU cycles.
Consequently, iOS, Android, Windows and BlackBerry enable C/C++ in the OS, and investments in C++-related technologies are ramping up. For example, Microsoft C++ AMP (C++ Accelerated Massive Parallelism) extends C++ syntax to allow parallel execution in the GPU and other heterogeneous cores. Likewise, Apple and Google, the top rivals of the post-PC era, co-sponsor Clang, a compiler front-end that accepts C and C++, among other programming languages.
C++ Readiness for the Post-PC Era
Even with the boost in C++ usage, it's important to note that it has positives and negatives in this new computing era. In addition to the aforementioned power advantages, it also delivers superior efficiency without compromising its inherent object-oriented abstraction power. The latest C++ standard, C++11, is simpler and more concise, thanks to features such as smart pointers and lambda expressions.
But this doesn't mean it's completely "simple and concise" yet. The C++ standard library covers a tiny fraction of its Java and .NET counterparts, leaving out such topics as GUIs, gestures, sensors, databases, XML, network protocols ... and the list continues. Consequently, developers are on their own to fill in those gaps.
Next, I'll assess the current status of C++ development for post-PC applications.
C++ is supported on all main platforms, although that support varies from one platform to another:
- iOS: Apple's sponsored Objective-C and C++ components can interact with Objective-C++. A helpful article about bridging the two languages is available here.
- Android: Google delivers a native development kit (NDK) beside its Dalvik Java-based software development kit (SDK). Interoperability is possible with the Java Native Interface (JNI).
- Windows and Windows Phone: C++/CX is an intermediate language that can be mixed with native C++ to enable access to the platform APIs. These APIs aren't the same for tablets and smartphones, so portability requires some extra work.
- BlackBerry: A complete C++ framework is available, in addition to non-C++ options.
iOS and Android hold around 90 percent of the post-PC segment. IDC expects Microsoft to be the third ecosystem by 2016.
A bigger user base could drive higher revenue, but doesn't guarantee it. Android surpassed iOS years ago, but different studies confirm that developers make more money from the Apple App Store than from Google Play. The gap is closing, though.
Consumer habits determine the best strategy for profitability, and there isn't one "best answer." You can charge for the app, or make the app free but add premium features or ads, and so on.
Compilers and IDEs
Three main C++ compilers are available for ARM: Clang, GNU Compiler Collection (GCC) and Visual C++; none of them completely supports C++11.
- iOS currently uses Clang, the most C++11-compliant compiler. The Apple Xcode IDE only runs on Mac OS X.
- Android has the most flexible SDK. You can choose between GCC or Clang. Google delivers a plug-in for Eclipse CDT (C/C++ Development Tooling). You can develop Android applications in Mac OS X, Linux or Windows.
- Windows -- Visual C++ is Microsoft's exclusive compiler and IDE. Windows tablet applications can only be created in Windows 8.
- BlackBerry has its own C++ compiler and QNX Momentics, an Eclipse-based IDE. Developers can choose between Mac OS X, Linux or Windows.
Platform-Neutral Frameworks and Libraries
There are a lot of platform-neutral community projects intended to complement the C++ standard (please let me know about any other open source projects I've missed here).
- Boost: Like Apache Commons in the Java world, this is the most influential C++ library, in the sense that many of its features helped shape new standard APIs (for example, smart pointers).
- Qt: This is a cross-platform application framework and IDE (Qt Creator) that helps share code between smartphones and desktops. The native BlackBerry framework is based on it. iOS and Android support is coming in 2013.
- Ogre3D: This is a rendering engine that bridges the gap between DirectX (the graphic API used by Windows) and OpenGL ES (all the others). These technologies encapsulate GPU access to accelerate rendering in graphics-intensive applications such as games.
These tools enable multi-targeting from a single codebase (as before, please let me know about any missing from this list):
- MoSync: This enables cross-platform, mobile C++ development in Android, iOS and Windows Phone 7. It comes with an IDE based on Eclipse, but requires the original platform tool chain to produce deliverables (C# for Windows and so on).
- Embarcadero C++Builder XE3: This promises a way to share a common code base between the major post-PC platforms. For the moment, it shares code between Mac, Linux and the Windows desktop. Its compiler is based on Clang.
The Soil Is Ready: Plant Some Seeds
Tablets and smartphones are fertile soil, ready to be seeded with applications. C++ fits well because it efficiently runs in the ARM architecture of tablets and smartphones -- which is why all the big players enable C++ in their SDKs. But because the standard language doesn't cover things like gestures, sensors and the UI, developers need to fill in those missing functionality blanks using non-standard, platform-specific APIs like the Apple Cocoa framework or the Windows Runtime Library. Fortunately, there are third-party frameworks, libraries and tools to help maximize the cross-platform area. Are you ready for some post-PC development?
Diego Dagum is a software architect and developer with more than 20 years of experience. He can be reached at firstname.lastname@example.org.