[chbot] Any ARM savvy people?

Volker Kuhlmann list0570 at paradise.net.nz
Wed Oct 12 00:01:28 BST 2016


On Wed 12 Oct 2016 10:16:17 NZDT +1300, Robin Gilks wrote:

>     crc = CRC_CCITT_INIT_VAL;
>     p = (uint8_t *)RegPointer;
>     for (i = 0; i < sizeof(RegisterFile); i++)
>        crc = updcrc_ccitt(*p, crc);

> So easy to miss a declaration half a page away!

Totally. So don't do it. Back in the days the style police required all
declarations to be at the top, because before those days compilers
couldn't do any better. IMHO it's misguided to declare a variable that
has a scope of 2(!) lines half or a full screen away, because it
encourages exactly the problem you have found. It's not legible either.

Better:

     crc = CRC_CCITT_INIT_VAL;
     p = (uint8_t *)RegPointer;
     for (uint8_t i = 0; i < sizeof(RegisterFile); i++)
	crc = updcrc_ccitt(*p, crc);

Which gives you a good chance of seeing that i will bomb out at 256
because you have all relevant information where you need it.

> to 8 bits and to keep the extra warning flags in the Makefile!!

Some people say warnings are just a nuisance, the compiler should just
shut up and create a runnable binary right now. I'd say code full of
warnings is not up to scratch, it has a high bug count and is not
maintainable.

That's why I said lots of Arduino code is rubbish (referring to the
official IDE supplied parts). It's at hobby level, not professional.
Pretty bad actually for something that makes educational claims,
teachers should do competently what they teach.

Volker

-- 
Volker Kuhlmann
http://volker.top.geek.nz/	Please do not CC list postings to me.



More information about the Chchrobotics mailing list