booleans and memory
quick question. how memory boolean take up? seems simple: 1 bit. i'm not familiar c, if arduino's programming built on c, "does not have distinct boolean type -- int used instead", mean every boolean in arduino code , int , takes 32 bits? boolean arrays?
here's trick:
if run you'll find booleans 1 byte each. int on avr 2 bytes, not 4.
sizeof() c builtin tells size (in bytes) of type.
the smallest addressable unit byte. if want try tricks storing "array" of 8 bits in byte can so, avr (and every other architecture i've ever worked on or read about) uses @ least 1 byte per element.
-j
code: [select]
serial.println(sizeof(boolean), dec);if run you'll find booleans 1 byte each. int on avr 2 bytes, not 4.
sizeof() c builtin tells size (in bytes) of type.
the smallest addressable unit byte. if want try tricks storing "array" of 8 bits in byte can so, avr (and every other architecture i've ever worked on or read about) uses @ least 1 byte per element.
-j
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > booleans and memory
arduino
Comments
Post a Comment