> Markdown version of [/videos/616-c-features-you-might-not-know](https://www.wearedevelopers.com/videos/616-c-features-you-might-not-know). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # C++ Features You Might Not Know Did you know using the unary plus operator forces lambda conversions? Discover terrifying syntactic anomalies like array index commutativity. Understand these hidden edge cases to master C++ mechanics. - **Speakers:** [Jonathan Müller](https://www.wearedevelopers.com/@jonathan-muller) - **Event:** World Congress 2023 - **Published:** August 11, 2023 - **Duration:** 24:13 - **URL:** https://www.wearedevelopers.com/videos/616-c-features-you-might-not-know ## Summary A deep dive into the obscure, often terrifying, yet surprisingly powerful edge cases of C++ syntax and semantics exposes features that most developers rarely encounter. While many of these quirks are considered intentionally horrifying or bad practices, understanding them sheds light on the language's underlying mechanics. The exploration spans syntactic anomalies like array index commutativity, the practical use of the unary plus operator to force lambda-to-function-pointer conversions, and leveraging the comma operator to manipulate parameter packs in fold expressions. Control flow in C++ harbors its own set of peculiarities. For instance, the commonly used else-if is not a native language construct but merely an else block containing a single if statement. Switch statements prove remarkably flexible since they do not strictly require braces, can position the default case anywhere, and even allow unreachable statements before the first label, enabling clever macros to assert missing defaults or construct classic patterns like Duff's device. At the function level, function try blocks provide a specialized syntax specifically designed to catch exceptions thrown during class member initializer lists. Memory layout and type safety principles reveal further intricacies. By exploiting the common initial sequence rule, developers can safely read inactive union members, seamlessly optimizing memory footprints without violating strict aliasing. Type casting offers hidden utilities, such as using a dynamic cast to a void pointer to retrieve the absolute memory address of the most derived object in a complex class hierarchy. Furthermore, mathematical operations require distinct caution because of two's complement representation, meaning dividing or taking the modulo of the minimum integer by negative one inherently triggers undefined behavior via integer overflow. Even standard library artifacts like valarray, originally designed for highly optimized element-wise matrix mathematics using expression templates, remain largely forgotten despite their built-in efficiency. **Keywords:** c++ syntax edge cases, array index commutativity, lambda function pointer conversion, comma operator fold expressions, c++ switch statement quirks, duff's device implementation, function try blocks, floating point nan boxing, c++ declaration specifiers, valarray optimization, dynamic cast void pointer, union common initial sequence, integer overflow undefined behavior, two's complement modulo errors, sizeof operator precedence ## Chapters 1. **Commutative property of array indexing operators** (02:24) — Pointer arithmetic definitions allow basic array indices to be evaluated commutatively. 1. **Unary plus for integral promotion and lambda conversions** (03:03) — Prefixing variables with unary plus operators forces underlying numeric integral promotion and transforms capturing lambdas into regular function pointers. 1. **Processing parameter packs using the comma operator** (04:27) — The comma operator sequences code execution chronologically and enables efficient parameter pack iteration through specialized fold expressions. 1. **The underlying syntax structure of else-if blocks** (05:29) — Chaining conditional statements together technically relies entirely on evaluating nested control blocks instead of using a dedicated else-if language syntax. 1. **Hidden mechanics of switch statements and local scope** (06:16) — Placing hidden statements safely before switch labels enables local scope instantiation while custom macros efficiently validate missed default case paths. 1. **Manipulating floating point exceptions and nan boxing payloads** (09:52) — Accessing hardware division flags enables runtime mathematical state checks while manipulating unused bits opens space for creating customized boxed memory structures. 1. **Arbitrary ordering of declaration specifier sequences** (11:52) — Reordering type specifiers arbitrarily alongside implicitly initialized function variables remains perfectly permissible under the compiler's flexible syntax evaluation rules. 1. **Catching constructor exceptions using function try blocks** (13:44) — Moving error-handling catch statements completely outside the class initialization body provides functionality to explicitly trap exceptions thrown during early class construction. 1. **Optimizing dynamically sized vectors with the valarray container** (14:31) — The valarray type handles raw mathematical arithmetic more efficiently by intelligently applying built-in compiler non-aliasing assumptions via execution expression templates. 1. **Casts to void pointers for finding derived addresses** (15:40) — Utilizing a dynamic hierarchy downcast converting entirely to a single void pointer correctly queries the target memory address pointing to the most derived layout object. 1. **Sharing memory safely via the common initial sequence** (16:55) — Defining identically formatted structure payload components directly at the start of multiple given union elements ensures completely safe retrieval access to underlying tag byte representations. 1. **Undefined behavior edge cases in modular integer arithmetic** (19:01) — Standard mathematical modulo operations trigger deeply surprising integer hardware overflows when specific execution limits encounter invisible internal fraction cycles. 1. **Exploiting operator precedence conflicts in size computations** (21:30) — Compiler unary operator parsing strictly evaluates before string array index operations thereby yielding solely array character sizes instead of evaluating final specific data lookups. ## Related Moments - [Evaluating the true impact of bad JavaScript features](https://www.wearedevelopers.com/videos/1451-best-of-the-worst-the-most-awful-anti-features-in-javascript-ranked) (from "Best of the Worst – the most awful anti-features in JavaScript, ranked!") - [Clarifying best practice patterns during structural syntax tool discussions](https://www.wearedevelopers.com/videos/696-don-t-compromise-on-speedy-delivery-nor-type-safety-by-choosing-typescript) (from "Don't compromise on speedy delivery nor type-safety by choosing TypeScript") - [Introduction to programming language internal workings](https://www.wearedevelopers.com/videos/692-making-sense-of-programming-languages) (from "Making Sense of Programming Languages") - [History of C++ technical debt and language design](https://www.wearedevelopers.com/videos/847-eternal-sunshine-of-the-spotless-programming-language) (from "Eternal Sunshine of the Spotless Programming Language") - [Introducing five core strengths of the programming language](https://www.wearedevelopers.com/videos/181-101-brilliant-things-of-c) (from "101 brilliant things of C++") - [Managing compilation performance and implementation specifics of advanced typing](https://www.wearedevelopers.com/videos/455-where-we-re-going-we-don-t-need-javascript-programming-with-type-annotations) (from "Where we're going we don't need JavaScript - Programming with Type Annotations") ## Related Articles - [Modern Java Switch Expressions](https://www.wearedevelopers.com/magazine/40-modern-java-switch-expressions) - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Dev Digest 130 - The Diablo is in the details](https://www.wearedevelopers.com/magazine/470-dev-digest-130-the-diablo-is-in-the-details) - [Dev Digest 124 - None like it hot](https://www.wearedevelopers.com/magazine/460-dev-digest-124-none-like-it-hot) ## Related Jobs - [Software Developer (f/m/d) C/C++](https://www.wearedevelopers.com/jobs/48105-software-developer-f-m-d-c-c) at **Power Plus Communications** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1465908-principal-software-engineer-database-infrastructure) at **GitHub** - [Principal Software Engineer, Identity](https://www.wearedevelopers.com/jobs/ext/1469181-principal-software-engineer-identity) at **GitHub** - [Hardware-naher Algorithmenentwickler](https://www.wearedevelopers.com/jobs/ext/1684535-hardware-naher-algorithmenentwickler) at **ZEISS Group**