common bugs in C programs

John Hascall hascall at cs.iastate.edu
Wed Jan 10 08:57:29 AEST 1990


In article <430009 at hpqtdla.HP.COM> malkie at hpqtdla.HP.COM (Malcolm Rix) writes:
 
}As we all know 'C' is a language riddled with potential problems and
}pitfalls for the unwary. While developing code and reviewing the work of others
}in the common firmware group we have been collecting a list of the most
}frequent problems:
 
}(14) Assuming x<<2 is the same as x*2. (Its actually x<<1).
}(15) Substituting shifts for multiplies by powers of 2 in expressions
}     without taking taking care of change in operator precedence.

      also be very careful with >> as a low-budget divide

}(24) Forgetting address arithmetic is done in multiples of the size of
}     the objects to which the pointers point.
}     I.e: int *a;   a++;  /* Points to next WORD not next BYTE */
					     ^^^^
                                           may not be a WORD!!

  John Hascall  /  ISU Comp Ctr



More information about the Comp.lang.c mailing list