I'm basically new to C++, aside from attempting to learn the language over 10 years ago and giving up, as I didn't really have a project to motivate me... Anyways, I'm just stating that I'm pretty much a n00b to C++ to let you guys/gals know my current knowledge level. That said, I am fairly proficient with Python and PHP. And since both of those languages are loosely typed, I am not that familiar with the impact type casting in C++ has on executable size, if any.

I am writing an Arduino program to take some data from a couple of ultra-sonic distance sensors and apply the data to a servo control algorithm. No problems with that, but I am now trying to optimize my code, as I'm getting close to the Arduino Micro's limit of 28,672 bytes. My first thought was to change my data types wherever possible to things like short int's and char's, expect it to have either no effect, or to slightly reduce my executable size. What I found is that the executable actually increased in size, after these changes, by a few hundred bytes.

Could someone with more C++ knowledge than I kindly help me understand the reason for this, and why I should, or shouldn't, even bother trying to choose the smallest possible data types for my variables? Obviously the results dictate what I *should* do here, but I really like to understand the 'why' behind things, and after some Googling, I still came up unsure.

Also, if it's not too much to ask; does anyone have some tips, or a link to some info on optimizing C++ code for limited-memory micro-controllers such as the Arduino?