Problems with typedef variable init'ing in c++
charles lombardo
lombardo at sun1.cs.nps.navy.mil
Wed Jun 26 07:43:20 AEST 1991
If I compile the following program with the C compiler, everything works fine.
<> typedef float Matrix[4][4];
<>
<> extern void unit();
<>
<> main()
<> {
<> Matrix m;
<>
<> unit(m);
<> }
<>
<>
<> void unit(m)
<> Matrix m;
<> {
<> static Matrix un = { 1.0, 0.0, 0.0, 0.0,
<> 0.0, 1.0, 0.0, 0.0,
<> 0.0, 0.0, 1.0, 0.0,
<> 0.0, 0.0, 0.0, 1.0 };
<> int i,j;
<>
<> /* copy the matrix elements...*/
<> for(i=0; i < 4; i++) {
<> for(j=0; j < 4; j++) {
<> m[i][j] = un[i][j];
<> }
<> }
<> }
The problem is when I compile the same program slightly changed for the C++
compiler. Namely:
<> typedef float Matrix[4][4];
<>
<> extern void unit(Matrix);
<>
<> main()
<> {
<> Matrix m;
<>
<> unit(m);
<> }
<>
<>
<> void unit(Matrix m)
<> {
<> static Matrix un = { 1.0, 0.0, 0.0, 0.0,
<> 0.0, 1.0, 0.0, 0.0,
<> 0.0, 0.0, 1.0, 0.0,
<> 0.0, 0.0, 0.0, 1.0 };
<> int i,j;
<>
<> /* copy the matrix elements...*/
<> for(i=0; i < 4; i++) {
<> for(j=0; j < 4; j++) {
<> m[i][j] = un[i][j];
<> }
<> }
<> }
When I compile the above I get the following message:
<> "tmp2.c", line 7: warning: m used but not set
<> "tmp2.c", line 15: error: bad initializer type for un: double
<> ( float (*)[4] expected)
<> "tmp2.c", line 15: error: initializer list too long
Can anybody explain why I cannot initialize the static Matrix variable.
I have gotten around the problem by initializing a static float[4][4]
variable instead, but this leaves a little bit to be desired. The Matrix
typdef is done in a system include file and it would be nice if these
guys could be initialized as in the code above.
Details: SGI IRIS 4D Machine (gl.h contains the typedef for Matrix)
AT&T C++ 2.0
Any comments are appreciated.
Thanks, Chuck
----------------------------------------------------------------------------
| Charles P. Lombardo | lombardo at cs.nps.navy.mil |
| Computer Science Department | voice: 408-646-2102 |
| Naval Postgraduate School | fax: 408-646-2814 |
----------------------------------------------------------------------------
More information about the Comp.sys.sgi
mailing list