APPENDIX: Programming hints

Defines aren't Functions

Watch out for multi-line defines in single line if, while, and for blocks. Results may not be what you expect! Example:

#define FOO(A) func1(A); func2(A);

int main() {
  // ...
  if( a )
    A(a);
}

will turn out to be

  if(a)
    func1(a);  // called only if a!=0
  func2(a);;   // always called! note obsolete ';'!

Preprocessor output

To see what comes out of the preprocessor as it would go into the compiler:

cc -Wall -g -I. -E source.c | less

To see what comes out of the preprocessor as it would go into the compiler but with all the #define statements left in (i.e., all #define statements are shown where they appear in the source code, but the preprocessor has replaced the occurrences in the text. this is a debugging option.):

cc -Wall -g -I. -E -dD source.c | less


Generated on Wed Apr 29 11:12:32 2009 for BTnut System Software by doxygen 1.5.1
!!! Dieses Dokument stammt aus dem ETH Web-Archiv und wird nicht mehr gepflegt !!!
!!! This document is stored in the ETH Web archive and is no longer maintained !!!