From 3cdceb2d3ec67d8f96528f4cbc0a16a06b2f7fe4 Mon Sep 17 00:00:00 2001 From: reid Date: Tue, 26 May 1998 22:12:51 +0000 Subject: [PATCH] [project @ 1998-05-26 22:12:51 by reid] Added: o more debugging hints (make rare things happen often) o another inline function advantage (gdb can execute them) o warning about int* p,q not declaring two pointers --- docs/coding-style.html | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/docs/coding-style.html b/docs/coding-style.html index ba93509..ceca6b9 100644 --- a/docs/coding-style.html +++ b/docs/coding-style.html @@ -191,6 +191,16 @@ an int to a nat, add an assertion. If you're casting an int to a char, add an assertion.
  • +Write special debugging code to check the integrity of your data structures. +(Most of the runtime checking code is in src/Sanity.c) +Add extra assertions which call this code at the start and end of any +code that operates on your data structures. + +
  • +When you find a hard-to-spot bug, try to think of some assertions, +sanity checks or whatever that would have made the bug easier to find. + +
  • When defining an enumeration, it's a good idea not to use 0 for normal values. Instead, make 0 raise an internal error. The idea here is to make it easier to detect pointer-related errors on the assumption that @@ -204,7 +214,14 @@ typedef enum ... +
  • Use #warning or #error whenever you write a piece of incomplete/broken code. + +
  • When testing, try to make infrequent things happen often. + For example, make a context switch/gc/etc happen every time a + context switch/gc/etc can happen. The system will run like a + pig but it'll catch a lot of bugs. +

    Syntactic details

    @@ -315,6 +332,10 @@ of side effects, evaluation order, multiple evaluation, etc.
  • Inline functions have call-by-value semantics whereas macros are call-by-name. You can be bitten by duplicated computation if you aren't careful. + +
  • You can use inline functions from inside gdb if you compile with + -O0 or -fkeep-inline-functions. If you use macros, you'd better + know what they expand to. However, note that macros can serve as both l-values and r-values and @@ -379,10 +400,31 @@ in the library.
  • -Try to use ANSI C's enum feature when defining lists of constants of the -same type. You'll notice that gdb works better when you do this. -For example: +This code +
    +int* p, q;
    +
    +looks like it declares two pointers but, in fact, only p is a pointer. +It's safer to write this: +
    +int* p;
    +int* q;
    +
    +You could also write this: +
    +int *p, *q;
    +
    +but Alastair prefers to split the declarations. + +
  • +Try to use ANSI C's enum feature when defining lists of constants of +the same type. Among other benefits, you'll notice that gdb uses the +name instead of its (usually inscrutable) number when printing values +with enum types and gdb will let you use the name in expressions you +type. +

    +Examples:

         typedef enum { /* N.B. Used as indexes into arrays */
          NO_HEAP_PROFILING,		
    -- 
    1.7.10.4