doc/guides/misc/dev_best_practices.md
ccache to speedup compilationDEVELHELP and CREATE_STACKTEST.unsigned, int, size_t or ssize_t) for loop variables wherever possible,
but keep in mind that on some platforms an int has a width of only 16-bit. In general, you should avoid types
like uint8_t for loop iterators as they will probably make it more expensive on some platforms.size/length parameters when passing memory, e.g. using sizeof(x) or strlen(x) as appropriate.
Make sure you don't use the wrong one with a pointer.true/false conditions.lock/unlock, acquire/release, ...) are always closed on every code path.assert() statements to check parameters rather than returning an error code at run-time,
to keep the code size down.DEBUG(...) macro rather than log_x(...)staticint/unsigned is only 16-bit on msp430 and avr8. If in doubt,
use portable types.static inline functions and macros. If they are used in multiple places,
is the increase in performance worth the penalty in code size?typedef enum {
A,
B,
...
} foo_t;
int bar(foo_t v)
{
int abc;
...
switch(v) {
case A:
abc = 23;
break;
case B:
abc = 42;
break;
...
}
...
}
/* VS */
typedef enum {
A = 23,
B = 42,
...
} foo_t;
int bar(foo_t v) {
int abc = v;
...
}
sizeof(enum)
(most bitfields are 16 bits max, on most of our newer platforms, sizeof(enum) is however 32 bits).
This results in every assignment needed to be cast to either uint8_t or uint16_t. With macros you don't need to
cast since they are typeless. Making the enum packed makes its width unpredictable in terms of alignment issues,
when used in struct.! vs ~, or && vs &)The below methodology is recommended, using well-known de facto standard tools from the FLOSS community that are compatible with RIOT. Using the below workflow improves time-to-running-code compared to typical IoT software workflows (which can be as retro as "LED-driven" debugging).
In your C program you have to decide where the memory you want to use comes from. There are two ways to get memory in your C code:
malloc()/free() to get memory from the heap).Both ways have some drawbacks which are listed here.
If you want to analyze the static memory consumption of your code you can use
otm or make cosy.
malloc() and free() are implemented in your libc (RIOT on ARM: newlib/picolib)
sizeof(<RAM>)-sizeof(<static memory>)