C Tips
Vince Buffalo edited this page Feb 7, 2016
·
3 revisions
- How to C in 2016
- Ben Klemens's 21st Century C is good, though opinated. His book Modelling with Data is also terrific—using C, the GSL, and his Apophenia library to model data in C.
Include -Wconversion
in compiler flags to warn on implicit conversions. I was bitten by this (1.5 days wasted) having a bit of code that passed a double genetic map length (1.96) to a function:
recomb_t *recombine(segments_t *segments, int genlen, gsl_rng *rng);
rather than:
recomb_t *recombine(segments_t *segments, double genlen, gsl_rng *rng);
Compilers warn on unused function parameters, e.g. if your program doesn't use int argc, char *argv[]
. Define the UNUSED()
macro as below:
#define UNUSED(x) (void)(x)
and place it in your code like:
int main(int argc, char *argv[]) {
UNUSED(argc); UNUSED(argv);
return 0;
}