|
Home
CV Blog Photos book reviews downloads work links F.A.Q. interests travels trekking videogames programming playing miniatures fitness programming C, C++ Java Shell misc. guestbook |
PIC18F Software Project Survival Guide 2 2011-May-25 Wednesday 23:41 CEST This is the second installment on a series of post regarding software programming on PIC18F cpu family. You can find the first here. Compiler warnings are inadequate at best. For example you don't get any message if a function that return a non-void type has no return statement. On the contrary when you compare an unsigned int to 0 (and not 0u) you get a warning. And you get warning for correct code, for example you can't pass a T* to a const void* parameter without getting the warning, event if the two pointers have the same size and the same internal representation. This behavior makes your life hard if your programming guidelines require maximum warning level and no warnings and doesn't help you with real problems in your code. I use PC-Lint to spot real problems, but a run of gcc with some #define to handle non-standard constructs will spot most of them. About warnings I had to fight back my loathing of useless casts and add them just for shutting up the compiler. Given the poor state of the lad, I hadn't been able to write a static assertion macro. Usually you write such a macro by turning a boolean condition in a compile-time expression that can be either valid or invalid (e.g. declaring an array with -1 or 0 elements, declaring an enum and assigning the first value to 1/0 or 1/1...). I haven't found any way to get the compiler refuse any of these constructs. One of the worst part of the toolchain is that it can produce code that breaks some hardware limitation without a warning. For example the compiler relies on a global temporary area for computing numerical expressions (array access is a case). The code generated expects that the temporary area is entirely contained in a data memory bank. The compiler nor the linker are able to detect when this area falls across a data memory bank boundary and alert the programmer. This is nasty because you can get subtle problems or having a failing program just after a recompilation. Similarly the C startup code relies on a similar constraint for a group of variables, should they not fit in the same data memory bank, the initialization silently fails. It took me few minutes to rewrite the startup code initialization routine and can't see any noticeable slowdown. I would advise to:
Next time I'll write about linker and assembler. No comments yet Write your comment? |
|
|
This site and its content is (C) by Massimiliano Pagani |