Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-unix!quintus!sun!decwrl!labrea!aurora!amelia!ames!sdcsvax!sdcc6!ix426 From: ix426@sdcc6.ucsd.EDU (tom stockfish) Newsgroups: comp.lang.c Subject: Re: Allocating two dimensional arrays Message-ID: <3590@sdcc6.ucsd.EDU> Date: 21 Jan 88 23:13:56 GMT References: <419@nikhefh.hep.nl> <10278@mimsy.UUCP> Reply-To: ix426@sdcc6.ucsd.edu.UUCP (tom stockfish) Organization: University of California, San Diego Lines: 28 In article <10278@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: X X [code defining create_matrix() which returns "data_t **", a "matrix" of X the sort that "argv" is, and free_matrix() ] X X Exercises: X 1. How *does* it work? X 2. Modify it to create a four-dimensional matrix of size W by X by X Y by Z. X 3. Modify it to produce upper or lower triangular matrices, without X using any more calls to malloc, and without wasting space (no X `mem' elements left over). 4. Modify it so that it uses only *one* malloc() call, the pointer it returns can be handed *directly* to free() (no "free_matrix()" routine needed), and a "true" matrix (or rather, pointer to the first element of it) can be easily obtained so it can be sent to a fortran routine (assuming the fortran routine can operate on the transpose). Oh yes, it must be portable, too. (Solution to follow at later date). 5. Prove that #4 cannot be done portably if the type of the matrix is not specified at compile time. -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu