Go Down

Topic: 1-Bit and 24-Bit Integer Variables, Please (Read 771 times) previous topic - next topic


First, "Arduino" is not a programming language.  It's more of a "framework" based on standard C/C++
I'm very interested in this topic. When I first started with Arduino I though .ino files were written in Arduino language. As I realized how awesome microcontrollers are and made the decision to dive deeper into this world, I started looking at alternatives to Arduino. I felt that learning a proprietary "toy" language would be a waste of my time in the long run, as I reached the limits of what I could do with the language and decided to move on. Then I read that the Arduino language was C++. That was a big "aha!" moment for me, which made me confident that sticking with Arduino was the right decision.

When I've seen people talk about the Arduino language, it's usually done by beginners or people denigrating the Arduino project. I was aware that somewhere on the Arduino site they talk about the Arduino language, but I thought of that as perhaps just an attempt to make things seem less intimidating to a beginner who might just shut down at mention of C++. My belief was further reinforced by a Hackaday article from Elliot Williams, who always writes excellent articles:

Over the years, I've corrected people talking about the Arduino language here several times. I've thought that the impression that there is an Arduino language and an "Arduino compiler" was harmful to the learning process and led to misconceptions (perhaps like this discussion).

Recently, I submitted a proposal to Arduino about adding some text about C++ to the Arduino Language Reference pages. I was informed by a couple of very knowledgeable Arduino employees, whose opinions I respect, that .ino files are written in Arduino language, not C++:

I understand the sketch preprocessing process, but I never thought that it made enough of a difference to qualify the code written in .ino files as a new programming language. This made me realize that I have no clue where the line is on what becomes a new programming language. Although I've seen well thought out arguments about why there is no Arduino language, I've never seen one arguing the contrary. It would be interesting to see something like that written by someone knowledgeable on the subject of programming languages.


I don't think of it as a new language, more as a pidgin or creole - it isn't exactly C++, but one should just about be able to make oneself understood to a native speaker.
(Among the Koorie people from the Victoria outback in Australia, a solar eclipse is "Kerosene lamp b'long Jesus gone bugger-up". source: The Telegraph)

I don't think it qualifies as a dialect.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


May 20, 2019, 08:06 pm Last Edit: May 20, 2019, 08:17 pm by BrendaEM
The libraries that allow Arduino to cross-compile and load the code are quite and achievement. Dozens of boards use the Arduino's IDE. Because Arduino's language is unique, it is language. It may mostly be C, but that's not all it is.

My purpose in asking for the data types is not only for efficiency, but for readability. It could be said that manual bit packing is clever, but its code is ugly, and distracting from the larger program. A compiler could easily pack, in this case, 8 bits into a byte.

The problem comes with code trans-portability and readability when moving to a processor with a larger word length. If there was an auto-bitpacked variable, the same code would just be more memory efficient because the library/compiler would know the word length.

If 1-bit auto-bit packed variables as well as 24-bit integers were integrated into Arduino's...vocabulary--would you avoid using them, or would you use them?


Because Arduino's language is unique, it is language.
I wrote a library with some unique functions and typedefs. Did I create a new programming language?

It may mostly be C
There's more C++ than C.

If 1-bit auto-bit packed variables as well as 24-bit integers were integrated into Arduino's...vocabulary--would you avoid using them, or would you use them?
First of all, it's already been explained to you that we have 24 bit variables. Use them if you like. Case closed on that.

As for 1 bit variables, please provide a demonstration of how this should be implemented in Arduino's core library. Remember that we are using a standard C++ compiler. Arduino is not in the business of writing compilers (nor would you want them to be).


"bool" or "boolean" could be a single bit, except for C's desire to have basic types be pointable-to (and probably promotion issues, too.)   Then it would just work the same way that "bool" works now.
I'm not sure which Arduino library functions would actually need to behave differently for single-bit values, or which ones would benefit from being able to (what good is having a 1-bit variable if it takes a full register to pass to subroutines, and/or extra instructions to extract from RAM/etc?)

It's sort of a shame that none of the big-name compiler/;anguage gurus jumped on ARM's "bit-banding" feature as a way to provide full-featured 1-bit types.  (It seems it's been dropped from the ARM due to lack of interest.)  OTOH, the lack of 1-bit variables in any standard computer language that I know of probably means that it has seven more "problems" than the ones I've mentioned.

Go Up