New features in the GCC versions 4.3 and 4.4
New Builder
Recent versions of the GNU compiler include new features from the next C++ standard.
The new C++ standard, which is informally known as C++0x, is still in the process of being hashed out, but many features of the next generation C++ have already made their way into the GNU compiler (GCC) versions 4.3 and 4.4. You can enable these features by entering the -std=c++0x option.
Many of these new features are mature enough to use without worries. Users of the influential Boost libraries [1] will be familiar with most of the changes because a fair share of the new standard is based on Boost. The technical details are available in the draft version of the C++ standard [2] and in the "Draft Technical Report on C++ Library Extensions" (TR1) [3]. Read on for a look at some of the most important changes in recent versions of GCC.
New Functions
The C99 standard substantially raised the number of mathematical functions available. It stands to reason that all of these C functions should be available in C++. The cmath library under the new C++ standard incorporates the full set of C99 functions (Table 1), while defining many additional mathematical functions (Table 2). The new C++ standard also mandates that new C libraries, such as stdint.h (fixed-size integers) or fenv.h (direct access to the floating point unit), must be available in C++. The C++ names for these libraries are cstdint, cfenv, and so on. The definitions are all bundled in the std namespace.
New Containers
Several new containers also inhabit the new standard, starting with the hash-based variants of the associative containers set, multiset, and map. These containers were originally planned for the older standard, but the developers dropped them for want of time. The new standard includes the unordered_set and unordered_map libraries, which define the hash-based containers unordered_set, unordered_multiset, and unordered_map. The unordered name component indicates that a comparative operator is not needed in order to use these containers. The unordered_set class definition is as follows:
template<class Value, class Hash=hash<Value>, class Pred=std::equal_to<Value>, class Alloc=std::allocator<Value> > class unorderd_set { ... }
With the template parameters, you can select the allocator (as with any standard container), specify the comparative predicate (this defaults to ==), and specify the hash function. If no specific information concerning the data is available, the default settings are a useful choice. Hash-based containers are faster than their tree-based counterparts (Table 3). The array (a lightweight class for a C array) and forward_list (a singly linked list) classes are also new.
Intelligent Pointers
The current C++ standard includes auto_ptr, a pointer that deletes an object automatically when it loses its value. The auto_ptr class has many restrictions. Each object can have only one owner, and strange things can happen in copying operations. More specifically, you cannot store an auto_ptr in a standard container. Effectively, auto_ptr causes more problems than it solves. The new C++ standard gets rid of auto_ptr and introduces improved, intelligent pointers. The new intelligent pointers are:
- unique_ptr, which is most similar to the legacy auto_ptr. The object belongs exclusively to the pointer. unique_ptr gives programmers an exception-proof approach to storing a pointer in a function.
- shared_ptr is a universally deployable, intelligent pointer. Multiple shared_ptr can share an object. If the programmer deletes the last shared_ptr pointing to an object, the destructor for the pointer calls the destructor for the object.
- weak_ptr monitors the objects managed by shared_ptr. The weak_ptr has no rights for the object. Thus, it is up to the programmer to ensure that the object stays alive while the pointer is alive. The weak_ptr and the shared_ptr are identical to the intelligent pointers of the Boost libraries.
The intelligent pointer collection should lead to more efficient programming as developers learn the nuances of the various new options.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.