[chbot] Programming 8-bit microcontrollers
Paul Davey
plmdvy at gmail.com
Fri Sep 23 10:03:31 BST 2016
On Fri, Sep 23, 2016 at 3:34 PM, Volker Kuhlmann
<list0570 at paradise.net.nz> wrote:
> This is for AVR, but should hold for any 8-bit job. Spot the problems:
>
> static const uint16_t setting = 15*60;
This is a class so it defaults to private visibility for it's members
so there is no way to actually access them.
> class values {
> uint8_t a, b, c;
> uint32_t d;
> uint8_t e;
> uint16_t f;
> };
This is a C++11 aggregate initializer, but this doesn't work since
values has private non-static members (all of them since it is a
class, struct should probably be used instead or a single public:
visibility modifier placed at the start of the values declaration). If
these are sensible defaults for any instance of values these can be
supplied as default initializers for the fields in the declaration.
> static const values defaults {
> 50, 1, 10, 0xFFB070, 5, 0x03FF
> };
> void func() {
> unsigned long ms;
This multiplication will not be 32 bit and so will overflow then be
promoted to 32 bits for assignment.
> ms = setting * 1000;
> ...
> }
>
> The program doesn't work in 2 places.
>
> First solution wins a free copy of the night light firmware.
>
> First correct solution wins 2 free copies of the night light firmware.
>
> Prize giving on Monday...
>
> Volker
>
> --
> Volker Kuhlmann
> http://volker.top.geek.nz/ Please do not CC list postings to me.
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
More information about the Chchrobotics
mailing list