Optimising compiler?

4 views
Skip to first unread message

Andy from Workshopshed

unread,
May 8, 2014, 2:47:15 AM5/8/14
to lond...@googlegroups.com
If I write a calculation using constants does the compiler optimise that for me before sending it to the Arduino?

E.g.

c = 360 / 12

Or do I need to manually optimise it?

c = 30

Andy from Workshopshed

unread,
May 8, 2014, 5:39:51 AM5/8/14
to lond...@googlegroups.com
I think I've answered my own question. Arduino code is compiled by AVR-GCC which is in turn part of the GCC compiler collection which is reported to do a whole series of optimisations.

The reason for asking is I'm doing some work with stepper motors and clock face and it makes more sense to have constructs like Hours * (StepsPerRev / 12) than to have a whole series of different constants such as StepsPerHour, StepsPerMinute etc . So this means I can just have one value to change if I swapped out my motors with different ones. Obviously we don't want the microcontroller doing unncessary calcuations but if it's covered by the compiler then we can have the best of both worlds with clear/maintainable code and good performance/memory usage on the arduino.


Reply all
Reply to author
Forward
0 new messages