Page 231 - The Art of Designing Embedded Systems
P. 231

21 8  THE ART  OF  DESIGNING EMBEDDED SYSTEMS


                             Use  too many parentheses.  Never  let the compiler resolve  prece-
                        dence; explicitly declare precedence via parentheses.
                             Never make assignments inside  if statements. For example, don’t
                        write:

                             if  ((foo =  (char *)  malloc(sizeof *foo)) ==  0)
                                                                     )
                               fatal ( “virtual memory exhausted” ;
                             instead. write:


                             foo =  (char *)  malloc(size0f *fool;
                             if  (foo ==  0)
                               fatal “virtual memory exhausted” 1
                                     (
                             If you use # i f def to select among a set of configuration options,
                        add a final  #else clause containing an  #error directive  so that the
                        compiler will generate an error message if none of the options has been
                        defined:

                             #ifdef sun
                             #define USE-MOTIF
                             #elif hpux
                             #define USE-OPENLOOK
                             #else
                             #error unknown machine type
                             #endif


                             Assembly Formatting

                             Tab stops in assembly language are as follows:

                               Tab 1: column 8
                               Tab 2: column 16
                               Tab 3: column 32


                             Note that these are all in increments of 8, for editors that don’t sup-
                        port  explicit  tab  settings.  A  large  gap-16   columns-is   between  the
                        operands and the comments.
                             Place labels on lines by themselves, like this:

                             label :
                                      mov     rl, r2              ; rl=pointer to I/O
   226   227   228   229   230   231   232   233   234   235   236