Posts Tagged const

C++ For C# Developers: Part 15 – Struct and Class Permissions

Tags: , , , , ,

Today we’ll cover the last major topic of structs in C++: how we control access to them. We’ll talk about access specifiers like private, the “friendship” concept, and finally get around to the details of const.

Read the rest of this article »

2 Comments

Getting the Size of a Struct at Compile Time

Tags: , , , , ,

I continue to learn a lot by reading the C++ code that IL2CPP outputs. Like reading decompiled code, it gives some insight into what what Unity’s build process is doing with the C# we give it. This week I learned that sizeof(MyStruct) isn’t a compile-time constant like it is in C++. Because of that, IL2CPP generates some less-than-ideal C++ code every time you use it. Today’s article shows the process I went through to work around that issue and ends up with some code you can drop into your project to avoid the problem.

Read the rest of this article »

No Comments

Adding the const Keyword to C#

Tags: ,

Today’s article is not about the const keyword that C# already has. It’s about the const keyword that C++ has and how we can approximate it in C# to make our code safer. It’s a really powerful tool that’s often the default for C++ programmers, but we can take advantage of a similar strategy in C#. Read on to learn how!

Read the rest of this article »

3 Comments

From AS3 to C#, Part 3: AS3 Class Parity

Tags: , , , , , , ,

Picking up from last time, today we’ll finish off classes in C# from an AS3 perspective in preparation for next week when we delve into all-new concepts that aren’t in AS3 at all. Read on to learn the C# way to implement getters and setters, final functions and classes, const variables, and packages.

Read the rest of this article »

13 Comments

Compile Time Only

Tags: , , , , , ,

The const and final keywords only apply at compile time. Despite having written about const and final before, readers frequently ask me about these two keywords. Today’s article will answer the question and definitively show that these keywords only apply at compile time: not runtime. UPDATE: const is still just a variable as far as performance goes, but its protections do extend to runtime.

Read the rest of this article »

13 Comments

The Const Keyword

Tags: , , , , , ,

Amazingly, I’ve never covered the const keyword, but a couple of recent comments have prompted me to cover the subject in depth with today’s article.

Read the rest of this article »

12 Comments