Page 5 - C-Language
P. 5

Examples                                                                                            55
            /* */ delimited comments                                                                          55

            // delimited comments                                                                             56

            Commenting using the preprocessor                                                                 56

            Possible pitfall due to trigraphs                                                                 57

        Chapter 11: Common C programming idioms and developer practices                                      58

          Examples                                                                                            58

            Comparing literal and variable                                                                    58

            Do not leave the parameter list of a function blank — use void                                    58

        Chapter 12: Common pitfalls                                                                          62

          Introduction                                                                                        62

          Examples                                                                                            62

            Mixing signed and unsigned integers in arithmetic operations                                      62

            Mistakenly writing = instead of == when comparing                                                 62

            Incautious use of semicolons                                                                      64

            Forgetting to allocate one extra byte for \0                                                      64

            Forgetting to free memory (memory leaks)                                                          65

            Copying too much                                                                                  67

            Forgetting to copy the return value of realloc into a temporary                                   67

            Comparing floating point numbers                                                                  67
            Doing extra scaling in pointer arithmetic                                                         69

            Macros are simple string replacements                                                             70

            Undefined reference errors when linking                                                           72

            Misunderstanding array decay                                                                      74

            Passing unadjacent arrays to functions expecting "real" multidimensional arrays                   76

            Using character constants instead of string literals, and vice versa                              78

            Ignoring return values of library functions                                                       78
            Newline character is not consumed in typical scanf() call                                         79

            Adding a semicolon to a #define                                                                   80

            Multi-line comments cannot be nested                                                              81

            Overstepping array boundaries                                                                     83

            Recursive function — missing out the base condition                                               83

            Checking logical expression against 'true'                                                        85
   1   2   3   4   5   6   7   8   9   10