0

I'm looking for a complete list of the arithmetic types in the Arduino framework. On the Internet I found various incomplete lists: sometimes there is short, sometimes word, but other types are missing.

Could someone please provide an exhaustive list of the arithmetic data types in Arduino, including the C/C++ types and the Arduino-defined types (or aliases, e.g. the one created among others in Arduino.h with typedef uint8_t byte;) with a short description? If two types are identical please include both names in the list but making clear that they are the same.

2

You have integers in 8, 16, 32 and 64 bits, both signed and unsigned. You have float and double, which can be the same thing on some systems.

There are many names given to those variable types, some standard or ubiquitous, some vague or unique, or change depending on which type of CPU you are working with.

The names aren't important, since they only exist in the source code. All that matters is the underlying size. Names of the same underlying size and signedness are interchangeable at will.

For example:

  • uint8_t = unsigned char
  • int32_t = long = int on 32 but systems
  • uint16_t = unsigned short = int on 8 bit systems

As you can see int changes depending on the system you are on. So it is best to stick to specifically named types. I always use the [u]int[N]_t types.

So you have:

  • uint8_t
  • int8_t
  • uint16_t
  • int16_t
  • uint32_t
  • int32_t
  • uint64_t
  • int64_t

And:

  • float
  • double (if the compiler supports double on the platform you are compiling for, otherwise it is just float).

Arduino itself provides some more unique variable names that are completely nonstandard, such as byte for unsigned char.

In short (pun intended), stick to variables that specifically define their type if you are worried about how big they all are, and avoid all the rest.

For overloading the compiler will automatically "upscale" the variables to the best fitting available function (known as type promotion) unless functions are flagged as explicit, so you can have a function with a long parameter and pass any integer variable up to and including a long in size. The same with float / double types - if your function takes a double you can pass it a float. Useful when you don't know if the target provides a real double or not - just use double and it will work regardless with either double or float.

  • And all the _Fract and _Accum types in avr-gcc 4.8+. – Ignacio Vazquez-Abrams Aug 22 '17 at 19:14
  • GCC has introduced all sorts of weird and wonderful types for special jobs. I have never seen any of them actually be used. People tend to use assembly or DSP instructions for optimisation instead of strange types. – Majenko Aug 22 '17 at 19:42
2

The Arduino "language" is actually C/C++. GNU GCC and tool chain are used. The Arduino IDE uses a preprocessor to make it easier for beginners by removing some of the C/C++ requirements such as forward declaration of functions.

The GNU AVR GCC data types and representation, and the answer to your question can be found on the project Wiki page; https://gcc.gnu.org/wiki/avr-gcc

For C/C++ there are build-in data types but also a set of standards. One of the standard header files with data types is stdint.h. http://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html

Arduino.h and additional header files within the Arduino core libary contains the extensions or redefinitions made. The complete reference list; https://www.arduino.cc/en/Reference/HomePage

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.