Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The use in the blog post of this example, with 2d arrays in C implemented through pointers-to-pointers, perplexed me.

If you care about efficiency, you don't use pointers-to-pointers for rectangular matrices. You use 1D vectors and strides. For instance, this is how numerical linear algebra codes typically represent matrices. This approach also generalizes well to N-dimensional problems.

The pointers-to-pointers idiom is picked up by some people due to its use in Numerical Recipes. Of course, NR used it to make C look like Fortran, because they were comfortable with Fortran. Another NR artifact is the gyrations used to make C arrays appear to start at 1 rather than 0. Which is a hoot.

I agree with some comments above that the Fortran 90 matrix constructs are an improvement on C's capabilities.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: