ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Boolean could take only 1 bit in memory #1039

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
> What change would like to see?
"typedef bool boolean" instead of "typedef uint8_t boolean"

> Why?
Because boolean myarray[100] could take only 13 bytes instead of 100 thanks to 
the optimizer.
Also it would yield a compilation error when doing "boolean myvar = 7"

> Would this cause any incompatibilities with previous versions?
If some people store something else than true/false 1/0 in boolean values, yes.

The bad thing is that Arduino.h MUST then only be compiled as C++ instead of C.

> If so, how can these be mitigated?
Since there's C++ at the core of the Arduino library anyway (Stream comes to 
mind), why not compile everything with g++ ?

thanks for reading,
Charlot

Original issue reported on code.google.com by charlesg...@gmail.com on 8 Sep 2012 at 7:50

GoogleCodeExporter commented 9 years ago
Under what circumstances does the optimizer manage to pack arrays of bools ?
Does this require a newer compiler?
I added a "bool test[100];" to blink, along with some code to fill it up, and 
it used 100 bytes of memory...

Original comment by wes...@gmail.com on 9 Sep 2012 at 5:45

GoogleCodeExporter commented 9 years ago
Hi,
I thought arrays could be compressed like packed structs. One has to use 
vector<bool>. So on memory I'm wrong.

There's still the type checking advantage when using bool instead of boolean, 
but that's secondary I think.

The issue can certaintly be closed.

Original comment by charlesg...@gmail.com on 9 Sep 2012 at 8:39

GoogleCodeExporter commented 9 years ago
Closed as per discussion.  Not really possible to do in standard C/C++

Original comment by wes...@gmail.com on 30 Sep 2012 at 9:23