Posts Tagged union

C++ For C# Developers: Part 40 – Utilities Library

Tags: , , , , ,

Today we’ll continue to explore the C++ Standard Library by delving into its utility classes and functions. These extremely common tools provide us with basics like std::tuple whose C# equivalent is so essential it’s built right into the language.

Read the rest of this article »

4 Comments

C++ For C# Developers: Part 16 – Struct and Class Wrapup

Tags: , , , , ,

Today we’ll wrap up structs and classes by discussing a bunch of miscellaneous features: local classes, unions, overloaded assignment operators, and user-defined literals. C# doesn’t have any of these features, but it can emulate some of them. Read on to learn a bunch of new tricks!

Read the rest of this article »

2 Comments

Steal Some More Bits

Tags: , , ,

Today we continue stealing float bits, but in an entirely different way this time. We’ll end up with the ability to switch between float and 21-bit integer modes and to know which mode we’re in. We can do all of this without using any more than four bytes just by exploiting a little knowledge of the float data format. Read on to learn how!

Read the rest of this article »

No Comments

Steal Some Bits

Tags: , ,

With a bit of understanding and some C# trickery, we can exploit how float works to cram in a few more bits and make some big performance gains. Today we’ll see how to steal some of the bits from a float!

Read the rest of this article »

No Comments

Adding Unions to Burst

Tags: , ,

We’ve seen how to add unions to C#, but does this work with the new Burst compiler? Today we’ll put it to the test and see if it can handle some of the more advanced struct customization features in C#!

Read the rest of this article »

2 Comments

Handling Errors Without Exceptions: Part 2

Tags: , , , ,

Last week’s article introduced the Either class as an alternative to exceptions that makes it easy for functions to declare their error results in addition to their success results and for callers of those functions to handle both results. Today we’ll go further by linking together multiple functions to handle all the error cases almost transparently. Read on to learn how to make the most out of Either!

Read the rest of this article »

No Comments

Handling Errors Without Exceptions: Part 1

Tags: , , ,

Exceptions are the de facto way to handle errors in C#, but they have problems. Callers don’t know if the function they’re calling will throw an exception at all or which types of exceptions it’ll throw. Exceptions also introduce an alternative control flow that’s often hard for programmers to follow. They make our code slower too, even when never thrown! Today’s article introduces an alternative to exceptions to help solve all of these issues. Read on to learn a new way to handle errors!

Read the rest of this article »

2 Comments

Adding Unions to C#

Tags: ,

C and C++ have a great feature call the “union”. It’s like a struct except it only has one of the fields at a time. C# lacks this feature, but with some trickery it can be added in. Today’s article shows how to do that!

Read the rest of this article »

6 Comments