Skip to content

Commit 88276d9

Browse files
fenugrecgsigh
authored andcommitted
HACKING: separate assignment from program flow, endianess helpers
1 parent 99307b2 commit 88276d9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

HACKING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Random notes
7979
- Generally avoid assigning values to variables at declaration time,
8080
especially so for complex and/or run-time dependent values.
8181

82+
- Separate assignments from control flow. Example: Avoid the pattern
83+
if (var = func()) {...} as it complicates review and maintenance.
84+
8285
- Consistently use g_*malloc() / g_*malloc0(). Do not use standard
8386
malloc()/calloc() if it can be avoided (sometimes other libs such
8487
as libftdi can return malloc()'d memory, for example).
@@ -95,6 +98,9 @@ Random notes
9598
Do use g_try_malloc() or g_try_malloc0() for large (>= 1MB) allocations
9699
and check the return value.
97100

101+
- Endianness conversion: Prefer the common helpers that are provided in
102+
libsigrok-internal.h, such as read_u16be() etc.
103+
98104
- You should never print any messages (neither to stdout nor stderr nor
99105
elsewhere) "manually" via e.g. printf() or g_log() or similar functions.
100106
Only sr_err()/sr_warn()/sr_info()/sr_dbg()/sr_spew() should be used.

0 commit comments

Comments
 (0)