Calling C from D
Once a binding is complete, there are potential crash-inducing bugs to be on the lookout for. Incorrect linkage attributes, the wrong number of function parameters, or any given function parameter declared with the wrong size can all bring the house down when the problem function is called. These are issues on the implementation side. There are other potential problems on the user's side that can also cause crashes or unexpected behavior. That's the focus of this section.
D arrays and C arrays
The inherent difference between C arrays and D arrays is a potential source of both compile-time and runtime errors. Here, we'll see the major issues to be aware of.
Basic arrays
When a C function expects to take an array as an argument, the corresponding parameter is declared as a pointer. Take the following example:
#include <stdio.h> void printThreeInts(int *ints) { int i; for(i=0; i<3; ++i) printf("%i\n", ints[i]); }
It's common practice in C to require an array length...