Anything you may have declared as static or const, or written as a #define can now put into an anonymous namespace and have the same effect – anything defined in inside cannot be accessed outside of the ‘.cpp’ file that the namespace is in. Anonymous namespace are also called ‘unnamed namespaces’ because, as the name suggests, they are defined without a name:Īnonymous namespaces take the place of declaring things static. It’s also a nice way to consolidate things which only need to be accessed within the current file. In C++11, the anonymous namespace is now the preferred way to specify a variable, function, or class that is accessible only in the current file (ie., they have internal, rather than external, linkage). The concept of an anonymous namespace has been around for a while in C++, but it came to prominence with the introduction of C++11. One note, if you’re editing a ‘.cpp’ file, you’ll have to #include, but in a ‘.ino’ file, you don’t. These are aliases of the underlying types, so on Arduino Uno, int8_t is the same type as a char, and uint16 is the same size as an unsigned int. Int64_t/uint64_t - a signed/unsigned type that is exactly 64 bits in size. Int32_t/uint32_t - a signed/unsigned type that is exactly 32 bits in size. Int16_t/uint16_t - a signed/unsigned type that is exactly 16 bits in size. Int8_t/uint8_t - a signed/unsigned type that is exactly 8 bits in size. If you use int16_t for a variable you know it’s 16 bits, regardless of which Arduino is being targeted. ![]() There are both signed and unsigned versions. The old ways are still available and you can still use them, but at the very least, after reading this you’ll be more aware of the newer features as we start to see them roll out in Arduino code.Ĭ++11 introduced a series of fixed width integer types aliases that will give you the number of bits (in multiples of 8) you want. Using these features of the language you no longer have to worry about specifying a 16-bit variable, calling the wrong function with NULL, or peppering your constructors with initializations. The following are some techniques using new features of C++ that don’t add memory overhead, reduce speed, or increase size because they’re all handled by the compiler. Modern C++ allows us to write cleaner, more concise code, and make the code we write more reusable. To the average Arduino user, some of this is irrelevant, maybe most of it, but the language still gives us some nice features that we can take advantage of as we program our microcontrollers. ![]() Starting with the introduction of C++11, the language has made a huge step forward and things have changed under the hood. C++ has been quickly modernizing itself over the last few years.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |