delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/12/20:04:21

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: parse error
Date: Wed, 11 Jun 1997 01:22:23 -0400
Organization: Cornell University http://www.cornell.edu
Lines: 56
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <339E360F.3E9A@cornell.edu>
References: <865999452 DOT 18286 AT dejanews DOT com>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0029.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019