[geeks] Matrix code

Joshua D Boyd jdboyd at cs.millersville.edu
Thu Apr 18 22:34:04 CDT 2002


On Thu, Apr 18, 2002 at 11:16:27PM -0400, Greg A. Woods wrote:
> [ On Thursday, April 18, 2002 at 22:12:56 (-0400), Joshua D Boyd wrote: ]
> > Subject: Re: [geeks] Matrix code
> >
> > I'd have to translate it into C then though, so it seems hardly worth the
> > effort.
> 
> There's been a whole lot of noise about C++ code in this thread and now
> you're saying you're really trying to write C code to handle matrices?
> 
> Why didn't you say so in the first place!?!?!? ;-)

I'm doing multiple things.  One thing must be C++, but it isn't very 
sophisticated matrix handling (build a rotation matrix and pass it back to
the calling program for passing onto another library and multiplying that
rotation matrix against a vector).

The other thing I'm doing is more general.  I have a bunch of fixed size
matrix classes lieing around, but now I find I need more sophisticated 
features, like inverses, determinants, eigenvalues and eigenvectors, etc.  
This is stuff that is hard enough to write that I'd like to either find a 
suitable version out on the net, or I'll rewrite it using matrices of 
arbitrary sizes (so that I don't have to modify it for all the fixed size 
classes).  For this second project, I would accept either C or C++.

And I tend to use C and C++ more interchangably that I should.  When I say C
I might mean C and C++ (meaning either one I don't care).  If I say C++, I
always mean C++ though.
 
> If you happen to now have that C book I think I remember recommending to
> you before then you'll find in it what I believe to be a very lucid
> explanation of the realtionship between array element references and
> pointer dereferencing.
> 
> 	C: A Reference Manual
> 	Harbison & Steele
> 	0-13-326224-3 (fourth edition)
> 
> on page 124:
> 
> 	Second, array subscripting is defined in terms of pointer
> 	arithmetic.  That is the expression a[i] is defined to be the
> 	same as *((a)+(i)), where 'a' is converted to &a[0] under the
> 	usual unary conversions.  This definition of subscripting also
> 	means that a[i] is the same as i[a], and that any pointer may be
> 	subscripted just like an array.
> 
> on page 125:
> 
> 	The language places no limit on the number of dimesions an
> 	array might have
>      [[ .... ]]
> 	The expression t[1][2] is expanded to *(*((t)+1)+2)
> 
> I.e. Array subscripts _are_ pointer dereferences in C.  Traditional
> array notation is really just in C to help out the FORTRAN guys....

Aren't they just pointer dereferences in C++ also, except for when there is an
operator overload?  They act like they are.

-- 
Joshua D. Boyd



More information about the geeks mailing list