Mail Archives: djgpp/1997/06/12/20:04:21
nazgul AT hubb DOT com wrote:
>
> void multiply_vector_and_matrix( vector a, matrix b )
> {
> vector temp;
...
> a = temp;
> }
>
what do you mean "this works"? temp is created on the stack and the
memory it points to need not be valid after the function returns. same
is true for the following function, too.
> //This function won't compile.
>
> void make_translation_matrix( matrix a, float xdiff, float ydiff,
> float zdiff )
> {
> matrix temp;
> temp = { {1, 0, 0, 0},
> {0, 1, 0, 0},
> {0, 0, 1, 0},
> {-xdiff, -ydiff, -zdiff, 0} };
> a = temp;
> }
using matrix temp = { {1, 0, 0, 0},{0, 1, 0, 0},{0, 0, 1, 0},
{-xdiff, -ydiff, -zdiff, 0} };
will allow that code to compile, but you'll get the following warnings:
D:\djgpp\C> gcc m.c -o m.exe -Wall -pedantic -ansi -lm
m.c: In function `make_translation_matrix':
m.c:26: initializer element for `temp[3][0]' is not computable at load
time
m.c:26: initializer element for `temp[3][1]' is not computable at load
time
m.c:26: initializer element for `temp[3][2]' is not computable at load
time
m.c:26: initializer element for `temp[3]' is not computable at load time
think about why. i would recommend going through the C FAQ. there are
also widely available matirx math examples, at least look at the code.
--
Sinan
*******************************************************************
A. Sinan Unur WWWWWW
|--O+O
mailto:sinan DOT unur AT cornell DOT edu C ^
http://www.people.cornell.edu/pages/asu1/ \ ~/
Unsolicited e-mail is _not_ welcome, and will be billed for.
*******************************************************************
- Raw text -